Nest
Nest

Reputation: 341

Multiple or statement can be written as in, any way for multiple and statement in sql

select * from Table1 where fieldname = 'a' or fieldname = 'b' or fieldname = 'c' 

The above statement can be written as

select * from Table1 where fieldname in ('a', 'b', 'c')

Is there any way to shorthand 'and' statement

select * from Table1 where fieldname = 'a' and fieldname = 'b' and fieldname = 'c' 

Update: Consider the situation

fieldname ID
--------------------
a         1   
a         2
b         3
c         4  
b         5
a         6

Upvotes: 0

Views: 2145

Answers (1)

Himanshu
Himanshu

Reputation: 32612

It is even not possible logically.

For any record if the value of fieldname is 'a' then fieldname can not have value 'b' (i.e. fieldname = 'a' then fieldname != 'b'). That means fieldname can not have more than one value for a single record.

If you write WHERE fieldname = 'a' AND fieldname = 'b' AND fieldname = 'c' it will give you empty result.

So there is no way to shorthand AND.

Upvotes: 5

Related Questions