0

I have item_ID column which has this number inside (1,2,3,4,5,6,7,8,9).I am running this query now

SELECT * FROM `coupons` WHERE item_ID like '%17%'

Still it's finding row. It should not find any row if item_id is parsed 17. Is there any problem with my query?

Update enter image description here

SUN
  • 973
  • 14
  • 38

1 Answers1

0

Here is how LIKE would be used: http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html

I assume your item_ID is some numeric type, right? So you can use the = operator:

If it realy is varchar (which I do not recommand for an identifier variable, because of performance issues), you would use:

SELECT * FROM coupons WHERE item_ID = '17';

If you want to find IDs containing the substring 17 then your query is allright.

If you have a commaseperated list of your IDs as string in that field (which I do not recommand) you should try this:

SELECT * FROM coupons WHERE item_ID LIKE '%,17,%' OR item_ID LIKE '%,17' OR item_ID LIKE '17,%' ;

check your content of that itme_ID field. 117, 1710, ` etc. can be found with your query as well.

helle
  • 11,183
  • 9
  • 56
  • 83