所以我有一张表,其中一行包含类别以及其他行。
所以有:
id (post id)
category (news, videos, music, photos, tutorials, coming-soon, etc..)
title (title of post)
desc (short meta desc of post)
post (the actual post)
etc...
因此,例如,我想做的就是拉
music, videos and photos
类别中的所有帖子,而忽略其他所有内容。我现在拥有的方式是选择
WHERE category != 'news' AND category != 'tutorials' AND category != 'coming_soon'.... etc, etc.,
,但总共大约有12个类别,这意味着我要执行9次!有没有更好的方法来编写该WHERE语句,这样就不必引用其他所有语句,而只需引用我想要的语句即可?
我尝试了
WHERE category = 'videos' AND category = 'music' AND category = 'photos'
,但是似乎没有用。 最佳答案
您想要的逻辑是:
WHERE category = 'videos' OR category = 'music' OR category = 'photos'
更好的是,只需使用
IN
:WHERE category IN ('videos', 'music', 'photos')