Web Hosting Talk







View Full Version : SQL Help


UnknownGame
01-03-2007, 05:28 PM
Hello,

I need some help with SQL

I have a table with random dates for mulitple accounts between 1990-01-01 and 2007-01-03


For each account, I want to find their latest date before 2005-01-01

Example:
ID | Date
0001 1990-04-14
0001 1994-02-19
0001 2004-12-24
0001 2007-01-01
0002 2001-02-14
0002 2001-11-15
0002 2005-02-03

I want it to pull just the following

0001 2004-12-24
0002 2001-11-15

Can someone direct me in the right direction or what functions I need.

Sorry if it is unclear, I hope the example I made makes it more clear.

Thanks in advanced
-Jeff

juangake
01-04-2007, 03:49 AM
Try WHERE datefield BETWEEN ('1900-01-01' AND '2004-12-31')

The above is just a quick solution that I know it works. Have you tried doing a simple comparison like " datefield < '2005-01-01' " ?

Regards,

Juan

jimpoz
01-04-2007, 11:57 AM
select id, max(date) from example where date<'2005-01-01' group by id