Reputation: 1609
I would like to know how do I query a database to select all records that don't fall in a particular day. In this case, I want to select all records that are not wednesdays. My date column in MySQL database is "Date" ex. 2012-09-10.
My "pseudo" select is as follows:
SELECT * FROM mytable WHERE date NOT IN(SELECT* FROM mytable WHERE date = WED)
Does anyone know the correct syntax?
Upvotes: 0
Views: 125
Reputation: 3497
Try this query:
select * from mytable where dayofweek(date)!=4;
Upvotes: 0
Reputation: 8078
What you want is the WEEKDAY() function.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_weekday
2 = Wednesday
select *
from mytable
where date >= CURDATE() - INTERVAL 30 DAY and
WEEKDAY(date) <> 2
Upvotes: 2