Home > Backend Development > PHP Tutorial > 关于查询的一个有关问题

关于查询的一个有关问题

WBOY
Release: 2016-06-13 13:35:54
Original
956 people have browsed it

关于查询的一个问题

某表记录是这样的
id title cid
100 张三 2,3
101 李四 3,4
102 王五 12,13

如果搜索,条件是要查cid字段=2的记录

应该怎么写?

sql语句里的like应该不严谨,可能会把100和102这两条记录都查出来


------解决方案--------------------

SQL code
SELECT * FROM table WHERE FIND_IN_SET('2',cid);
<br><font color="#e78608">------解决方案--------------------</font><br>
mysql> select find_in_set(2, "2,3,4");<br>+-------------------------+<br>| find_in_set(2, "2,3,4") |<br>+-------------------------+<br>|                       1 |<br>+-------------------------+<br>1 row in set (0.00 sec)<br><br>mysql> select find_in_set(2, "52,3,4");<br>+--------------------------+<br>| find_in_set(2, "52,3,4") |<br>+--------------------------+<br>|                        0 |<br>+--------------------------+<br>1 row in set (0.00 sec)<br><br>mysql> select find_in_set(2, "2,3,4");  <br>+-------------------------+<br>| find_in_set(2, "2,3,4") |<br>+-------------------------+<br>|                       1 |<br>+-------------------------+<br>1 row in set (0.00 sec) <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template