One question about query a table record is this idtitlecid100 Zhang Weisan Li Si 3. 4102 Wang Wu 12, 13 if you search, the condition is to check the record with cid field = 2. how should I write it? The like in SQL statements should be not rigorous, and both 100 and 102 records may be found. an SQL query problem
This is the case for a table record.
Id title cid
100 sheets 3, 3, 3
101 Li Si 3, 4
102 Wang Wu
If you search, the condition is that you want to query records with cid field = 2.
What should I do?
Like in SQL statements should be not rigorous, and both 100 and 102 records may be found.
------ Solution --------------------
SQL code
SELECT * FROM table WHERE FIND_IN_SET ('2', cid );
------ Solution --------------------
Mysql> select find_in_set (2, "2, 3, 4 ");
+ ------------------------- +
| Find_in_set (2, "2, 3, 4") |
+ ------------------------- +
| 1 |
+ ------------------------- +
1 row in set (0.00 sec)
Mysql> select find_in_set (2, "52,3, 4 ");
+ -------------------------- +
| Find_in_set (2, "52,3, 4") |
+ -------------------------- +
| 0 |
+ -------------------------- +
1 row in set (0.00 sec)
Mysql> select find_in_set (2, "2, 3, 4 ");
+ ------------------------- +
| Find_in_set (2, "2, 3, 4") |
+ ------------------------- +
| 1 |
+ ------------------------- +
1 row in set (0.00 sec)