开发者

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

开发者 https://www.devze.com 2023-03-08 03:00 出处:网络
I have the following query: SELECT id,name FROM categ WHERE email_activated=\'1\' ORDER BY id D开发者_开发知识库ESC

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

精彩评论

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