challengeAccepted
challengeAccepted

Reputation: 7610

Not Equal to query for SQL server

I was trying to execute a query which gets me all the info from Merchant table where PackageID is not equal to 21 or 22 or 23..

Select * from Merchant where PackageID NOT '22' Union Select * from Merchant where PackageID Not '21'

Thanks!!

Upvotes: 4

Views: 7572

Answers (5)

Matt
Matt

Reputation: 3132

SELECT * FROM Merchant WHERE PackageID NOT IN ('21','22','23')

Upvotes: 1

faxi05
faxi05

Reputation: 325

SELECT * FROM Merchant WHERE Packageid NOT IN ('21', '22', '23')

Upvotes: 1

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171559

You can use the NOT IN clause for this:

select * 
from Merchant 
where PackageID not in ('21','22')

Upvotes: 0

Russ
Russ

Reputation: 4173

Select * from Merchant where PackageID NOT IN ('21', '22', '23')

Upvotes: 0

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25390

use PackageID NOT IN (21, 22, 23..)

 Select * from Merchant 
 where PackageID NOT IN (21, 22, 23)

Upvotes: 8

Related Questions