Possible Duplicate:
Searching a column containing CSV data in a MySQL table for existence of input values MySQL query findi开发者_Go百科ng values in a comma separated string
I have two tables. One table includes tags, the other table includes posts which have tags in a comma separated string. I need to get all posts with a specific tag id.
I tried this but it didn't work:
SELECT
ab_tags.id,
ab_tags.lang,
ab_tags.tag,
ab_tags.slug,
ab_etkinlik.title,
ab_etkinlik.tag
FROM
ab_tags ,
ab_etkinlik
WHERE
ab_tags.id = 2
ab_tags.id IN (ab_etkinlik.tag)
ab_tags.id is coming from $_get val
thanks in advance.
If you designed this schema yourself, you're missing the concept of a link-table. If you have tables called 'tags' and 'events' (etkinlik), you should probably have a two-column 'eventtags' link-table with zero-to-many rows for each event. First column is event id, second column tag id.
Try this:
SELECT ab_tags.id,
ab_tags.lang,
ab_tags.tag,
ab_tags.slug,
ab_etkinlik.title,
ab_etkinlik.tag
FROM ab_etkinlik
JOIN ab_tags ON ab_tags.tag IN(ab_etkinlik.tag)
WHERE ab_tags.id = 2
精彩评论