0

I am probably overlooking something simple--

Some of the news items has 2 categories checked, and other times it has all 4 check. I know I can do OR '' OR '' OR '' OR '' -- but I think there is a better way.

The question: How could I query this to output: if the story has category 10,13 or 10,13,15 or 10,13,15,16 or 10,15 or 10,13?? ('10' is the parent category) -- without doing a query like that??

WHERE news.id = story.post_id AND news.category LIKE '10,13,15,16'
1
  • Your schema perplexes me a bit. Perhaps category be its own table (categories) and then you can use a categories_news cross-reference table. Just a suggestion. Commented Oct 16, 2010 at 15:00

2 Answers 2

1

You could say:

AND new.category IN ('10,13', '10,13,15', '10,13,15,16', '10,15', '10,13')

Which is slightly cleaner that using many OR's.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I didn't realize you can query "IN" ha.
0
WHERE news.id = story.post_id AND news.category in (10, 13, 15, 16)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.