Reputation:
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
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
thx for help
Upvotes: 0
Views: 1717
Reputation:
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'
Upvotes: 1
Reputation: 135918
SELECT * FROM Table2, Table1
WHERE Table1.Id=$ID
AND FIND_IN_SET(Table1.Id, Table2.Table1ID) <> 0
Upvotes: 1