Home  >  Q&A  >  body text

A MySql query problem

Data are as follows:

id col
1 a,b,d
2 a,b,c

My query conditions:

col=(a,b) requires finding two rows with IDs 1 and 2

col=(a,d) Find the row with id 1

col=(a,c) Find the row with id 2

col=(a) Find two rows with IDs 1 and 2

Could you please tell me if you have any methods?

为情所困为情所困2711 days ago620

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-18 10:48:37

    Take the first one as an example.

    select * from tablename where find_in_set('a', col)>0 and find_in_set('b', col)>0;

    reply
    0
  • 阿神

    阿神2017-05-18 10:48:37

    1.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('b',col)

    2.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('d',col)

    3.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('c',col)

    4.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col)

    reply
    0
  • Cancelreply