Emile Cloete
Emile Cloete

Reputation: 163

SQL Select all except

I am trying to select all records from the trips table except the trips done by vehicle1 for contract1. Something like:

   SELECT * FROM trips
   WHERE vehicle != 'vehicle1'
   WHILE contract = 'contract1'

Upvotes: 2

Views: 444

Answers (4)

John Mark Howell
John Mark Howell

Reputation: 63

Maybe I'm not understanding but couldn't you do something like

SELECT * FROM trips WHERE NOT (vehicle = 'vehicle1' AND contract = 'contract1')

Upvotes: 0

Mureinik
Mureinik

Reputation: 311163

It seems like what you need is just the or logical operator to check that at least one of these conditions doesn't happen on the same row:

SELECT * 
FROM   trips
WHERE  vehicle != 'vehicle1' OR contract != 'contract1'

Upvotes: 0

Assaf
Assaf

Reputation: 1346

Use boolean operators (AND) - http://www.w3schools.com/sql/sql_and_or.asp

for example: where vehicle!='vehicle1' and contract = 'contract1'

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460068

You can use this

SELECT * FROM trips
WHERE vehicle <> 'vehicle1'
OR   contract <> 'contract1'

or this

SELECT * FROM trips
WHERE NOT (vehicle = 'vehicle1' AND contract = 'contract1')

Upvotes: 4

Related Questions