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

por*_*rjr -3 sql

我对此声明有疑问:

select * 
from texts 
where id in (1, 3) 
  and address in ('address_one', 'address_another');
Run Code Online (Sandbox Code Playgroud)

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

  • id = 1并且地址为'address_one'
  • id = 3并且地址为'address_another'

如果有办法做到这一点?

Rhy*_*nes 5

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

(id = 1 and address = 'address_one') or (id = 3 and address = 'address_other')
Run Code Online (Sandbox Code Playgroud)

另一种方法可能是;

(cast(id as varchar(32)) + '_' + address) in ('1_address_one', '3_address_other')
Run Code Online (Sandbox Code Playgroud)