I'm implementing a Tag system...
Currently i have the table tags with name, description, createdby fields.
And the table images that have a field tags. Inside this field i will put the tags name from the table tags, separated by comma.
But, if i want to get all images with tag Foo how i do form the query? since the field will contain multiple tags separated by comma.
Not sure if you have thought about normalizing the images table, but that would be the optimal solution here.
Instead of having

Structure your table this way

Then you can run this SQL statement to return all images with a certain tag
SELECT * FROM images
WHERE tags = 'forest';
Or if there is a reason you need to keep your table in the current format, you can use
SELECT * FROM images
WHERE tags LIKE '%forest%';
The word 'forest' in the above 2 examples is the tag you are searching for
Try something like that :
SELECT * FROM images WHERE tags = 'Foo' OR tags LIKE 'Foo,%' OR tags LIKE '%,Foo' OR tags LIKE '%,Foo,%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With