I am using php in my web site. Here i want to fetch a record in such a way that match against a comma separated values. Please read below example
I have two tables.
我在我的网站上使用php。在这里,我想以匹配逗号分隔值的方式获取记录。请阅读以下示例我有两张桌子。
-
Table 1 say user, which have a column name say
itemcode
表1说用户,其列名称为itemcode
eg:
id = 1 itemcode =3,10
id = 1 itemcode = 3,10
-
Table 2 say itemsList, which al so have itemcode field
表2表示itemsList,它具有itemcode字段
eg :
id=1 itemcode= 1,3,7,5, id=2 itemcode= 4,9,10 id=3 itemcode= 1,3,10,11 id=4 itemcode 2,3,7,10 id=5 itemcode 1,2,8,9
I need to display all the records from itemsList table which have itemcode 3 or 10
我需要显示itemsList表中包含itemcode 3或10的所有记录
ie need to display the records with ids = 1, 2,3,4
即需要显示ids = 1,2,3,4的记录
1 个解决方案
#1
0
You could use FIND_IN_SET function:
您可以使用FIND_IN_SET函数:
SELECT *
FROM yourtable
WHERE
FIND_IN_SET(3, itemcode) OR
FIND_IN_SET(10, itemcode)
Please see fiddle here.
请看这里的小提琴。
#1
0
You could use FIND_IN_SET function:
您可以使用FIND_IN_SET函数:
SELECT *
FROM yourtable
WHERE
FIND_IN_SET(3, itemcode) OR
FIND_IN_SET(10, itemcode)
Please see fiddle here.
请看这里的小提琴。