Stephani Bishop
Stephani Bishop

Reputation: 1609

Select all records that are not wednesday and are only 30 days old

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

Answers (2)

Markus Mikkolainen
Markus Mikkolainen

Reputation: 3497

Try this query:

select * from mytable where dayofweek(date)!=4;

Upvotes: 0

pyrospade
pyrospade

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

Related Questions