SQL在语法比较中按正确顺序排列

时间:2015-01-26 15:38:10

标签: sql

我对此声明有疑问:

select * 
from texts 
where id in (1, 3) 
  and address in ('address_one', 'address_another');

我想拥有满足这些条件的所有记录:

  • 的id = 1且地址为“address_one”
  • 的id = 3且地址为“address_another”

如果有办法吗?

1 个答案:

答案 0 :(得分:5)

您需要重新编写WHERE子句,如下所示;

(id = 1 and address = 'address_one') or (id = 3 and address = 'address_other')

另一种方法可能是;

(cast(id as varchar(32)) + '_' + address) in ('1_address_one', '3_address_other')