简体   繁体   中英

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.

Try:

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

See Fiddle .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM