How to use MySQL, how to find the exact value

I have a row that stores a column of the 'tbl_route' table named 'route_nos'.

The string looks like 3,4,7,8,9,10,11,14,16,20

I am looking for two numbers from this chain using MySQL LIKE.

$nosPos="1"; 
$qr=mysql_query("select * from tbl_route where routes_nos like '% $nosPos %'");

      

But when the query is executed, it returns rows. But there is no 1 in this line . I found that LIKE accepts a partial match of none, which is present in 11 or 14 or 16. But I need an exact search .. How is this possible?

+3


source to share


2 answers


Use

$qr=mysql_query("select * from tbl_route where FIND_IN_SET($nosPos, routes_nos) ");

      



Refer Doc here

+2


source


For an exact match, don't include the line inside% ..%, but use it directly:



$qr=mysql_query("select * from tbl_route where routes_nos like '$nosPos'");  

      

0


source







All Articles