开发者

How can I query only IDs 3, 4, 5 and 1?

I have the following query:

SELECT id,name
FROM categ
WHERE email_activated='1'
ORDER BY id D开发者_开发知识库ESC

but I only want to query for IDs 3, 4, 5 and 1.

How can I specify those IDs in the query?


Use an IN clause

SELECT id, name
FROM categ
WHERE email_activated='1'
AND id IN (1, 3, 4, 5)
ORDER BY id DESC

Ref: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜