Query OR Statement

50 views Asked by At

Can anyone help me with a query please? I am not sure how to add this OR statement

select id, status, from custom_Object__c where id in ('id1' or 'id2') 

I have also tried

select id, status, from custom_Object__c where (id = 'id1' or 'id2')

Can anyone tell me how to use an OR statement for 2 ids within IN statement? Thanks!

I have also tried

select id, status, from custom_Object__c where (id = 'id1' or 'id2')

Can anyone tell me how to use an OR statement for 2 ids within IN statement?

1

There are 1 answers

0
Adrian Maxwell On BEST ANSWER

To employ an OR condition in a where clause you can do this:

select id, status 
from custom_Object__c 
where (id = id1' OR id ='id2')

The IN construct in SQL can be used as a "shortcut", for example the equivalent of the above query is as follows:

select id, status 
from custom_Object__c 
where id in ('id1','id2') 

Here the you simply list out the values that id may equal separated by a comma (& you do not need to specify "or" in that list).