更清洁的方式来编写这个MySQL查询?

时间:2012-05-05 16:47:15

标签: mysql

这是我目前的查询:

SELECT * FROM users
WHERE blah blah...
AND users.who = '1'

AND users.seeking = '2' 
OR users.seeking = '5' 
OR users.seeking = '8' 
OR users.seeking = '9' 
OR users.seeking = '11' 
OR users.seeking = '13' 
OR users.seeking = '14' 
OR users.seeking = '15' 

AND users.account_status = '1';

如您所见,搜索字段可以包含多个值。而不是编写这么多OR,是否有一种更漂亮的方法来指定该字段的所有可接受的值,以便由我的select语句返回?

1 个答案:

答案 0 :(得分:11)

SELECT * FROM users
WHERE blah blah...
AND users.who = '1'

AND users.seeking IN('2','5','8','9','11','13','14','15') 
AND users.account_status = '1';