superphonic
superphonic

Reputation: 8074

MySQL SELECT all except where two columns have specific data together

Sorry the title is so confusing, below is my table (example) and what I am trying to achieve.

uid | title     | comment      | duration    | timestamp
---------------------------------------------------------
1   | test      | test         | d           | 2013-09-15 12:00:00
2   | test      | test         | w           | 2013-09-15 12:00:00
3   | test      | test         | m           | 2013-09-30 12:00:00
4   | test      | test         | y           | 2013-12-31 12:00:00
5   | test      | test         | d           | 2013-09-16 12:00:00

Basically I need a query that SELECT * from this table except when duration = d AND timestamp = 2013-09-15 12:00:00 together. So the only record that should be excluded from the results is row 1.

What I need seems so simple and I am sure I am missing something, but I am having a real hard time with it...

All help greatly appreciated.

Upvotes: 0

Views: 256

Answers (2)

dnoeth
dnoeth

Reputation: 60462

select * 
from table 
where not (duration = 'd' AND timestamp = '2013-09-15 12:00:00');

Upvotes: 3

xlecoustillier
xlecoustillier

Reputation: 16351

Try:

SELECT *
FROM yourTable
WHERE duration != 'd' OR timestamp != '2013-09-15 12:00:00';

See Fiddle.

Upvotes: 3

Related Questions