[英]SQL query - Fetch data from one column separated by comma
Hi I have problem with fetching data from one column separated with comma, 嗨,我从使用逗号分隔的一列中获取数据时遇到问题,
My problem is: 我的问题是:
Table1
ID | Cat
--------
1 | XY
2 | ER
3 | FF
Table2
Id | Text | Text2 | Table1ID | Text3 | text3
--------------------------------------------------
1 | -- | -- | 1,2,3 | --- | ---
2 | -- | -- | 3,1,2 | --- | ---
3 | -- | -- | 1,3,4 | --- | ---
I need SELECT query to fetch data from Table1 column Cat where Table1.ID=Table2.Table1ID and i got only one Cat but i need all from Table2.Table1ID 我需要SELECT查询从Table1列Cat获取数据,其中Table1.ID = Table2.Table1ID,我只有一只Cat,但我需要所有来自Table2.Table1ID
This is my query now: 这是我的查询:
SELECT * FROM Table2, Table1
WHERE Table2.Table1ID=$ID
AND Table2.Table1ID=Table1.Id
AND Table2.Table1ID
I only got one data from Table1ID and everything behind comma is invisible 我只从Table1ID获得一个数据,逗号后面的所有内容都是不可见的
thx for help 请求帮助
Well, sorry then. 那么,抱歉。 I misunderstood your explanation.
我误解了你的解释。
May not the better way but it may works: 可能不是更好的方式,但可能有效:
SELECT * FROM Table2 WHERE Table2.Cat Like '%$ID,%' OR Table2.Cat Like '%,$ID'
SELECT * FROM Table2, Table1
WHERE Table1.Id=$ID
AND FIND_IN_SET(Table1.Id, Table2.Table1ID) <> 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.