Forum Moderators: open

Message Too Old, No Replies

Matching date range regardless of years; combining queries

         

ntbgl

3:04 am on Feb 9, 2009 (gmt 0)

10+ Year Member



I have a two-fold question about a query.

If I have dates column and a "published" column, such as:

date, published
1911-04-26, y
1855-10-16, y
1941-10-20, y
1998-10-27, n
2004-10-27, n

Can I make a mysql query to get all the matches for the month, regardless of the year?

SELECT * FROM table WHERE date BETWEEN 'October-01' AND 'October-31'

Also, can I combine two queries into one super query? Such as:

SELECT * FROM table WHERE (published='y' AND date BETWEEN 'October-01' AND 'October-31') OR (published='n' AND date BETWEEN '1998-10-01' AND '1998-10-31') SORT BY date

Note on this demo combined query it searches the same table but years don't matter if published='y' where it does if published='n'.

physics

6:30 pm on Feb 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Isn't the fun in TRYING to see if these work ;)