[英]Searching for a number inside a column MySQL
I have a column in table "recipes" called "Products". 我在“食谱”表中有一列称为“产品”。 This is is filled like this: 这样填充:
460,450|50,100|243,500|141,5|457,100|383,211|
ProductID,ProductGrams| 产品ID,ProductGrams | is the format. 是格式。
Now i would like to search for an product with id 243 in the above example. 现在,我想在上面的示例中搜索ID为243的产品。 How can i do this? 我怎样才能做到这一点?
SELECT * FROM recipes WHERE Products LIKE '%243%'
Will also give me results if theres productgrams that are 243. 如果productgrams是243,也会给我结果。
How can i do this? 我怎样才能做到这一点? Im lost... 我迷路了...
Its ok if theres also php for a solution to this. 好的,如果还有php可以解决这个问题。
You could do 你可以做到
SELECT * FROM recipes WHERE Products LIKE '243,%' OR Products LIKE '%|243,%
But more importantly this data should be normalized in the database prior to being queried. 但更重要的是,应在查询之前在数据库中对这些数据进行规范化。
只需按自己的喜好包含分隔符,
SELECT * FROM recipes WHERE Products LIKE '%|243,%'
Maybe tthis will work? 也许这行得通吗?
SELECT * FROM recipes WHERE Products LIKE '%243,%'
Note the comma. 请注意逗号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.