Search code examples
mysqlfind-in-set

find_in_set AND find_in_set not working


Trying to pull this query off, but it won't take ?

SELECT cute_news.title, cute_news.id, cute_news.keywords, cute_fields.post_id, cute_fields.alternate_url 
FROM cute_news, cute_fields 
WHERE cute_news.id = cute_fields.post_id AND 
FIND_IN_SET ('37',cute_news.category) AND 
FIND_IN_SET ('45',cute_news.keywords)

Not sure if I can't have two instances of FIND_IN_SET or what ?


Solution

  • Do both these queries return some common results?

    Query 1

    SELECT cute_news.title, cute_news.id, cute_news.keywords, cute_fields.post_id, cute_fields.alternate_url 
    FROM cute_news, cute_fields 
    WHERE cute_news.id = cute_fields.post_id AND 
    FIND_IN_SET ('37',cute_news.category)
    

    Query 2

    SELECT cute_news.title, cute_news.id, cute_news.keywords, cute_fields.post_id, cute_fields.alternate_url 
    FROM cute_news, cute_fields 
    WHERE cute_news.id = cute_fields.post_id AND 
    FIND_IN_SET ('45',cute_news.keywords)
    

    Your query should return the intersection of Query 1 and Query 2. If either result set is empty, or if they have no results in common, then the final query will have no results.