Page 1 of 1
sql query
Posted: Wed Nov 05, 2003 9:07 am
by yaron
I can't believe I'm really asking this query but i can't seem to make this simple query to work.
I have a table with a DATE field and i want to gram the row that has tha max date field
something like that:
SELECT *
FROM table
WHERE date=MAX(date)

Posted: Wed Nov 05, 2003 9:19 am
by kendall
Yaron,
Maximum Date...? Can you get a maximum date?
You can get LAST date or a FIRST date
Code: Select all
SELECT * FROM table SORT date DESC LIMIT 1 // recent date
Code: Select all
SELECT * FROM table SORT date ASC LIMIT 1 // earlier date
propable you want has results that has similar dates
Code: Select all
SELECT * FROM table WHERE date = date // earlier date
then do a mysql_num_rows()
But im not sure if there is a MAX(date)
Can there?
Kendall
Posted: Wed Nov 05, 2003 9:27 am
by yaron
LOL,
u rae right... there is no max date is there?!
i meant the recent one of course...
Thanks..
Posted: Wed Nov 05, 2003 10:39 am
by JAM
Max() is for numbers (1, 1.2, 1.9, 2, 3.6, ..., 452,... , 9928831 etc.).
But dates are dates. Even tho I can agree that they do look like numbers, you can't use math-functions like max(), min(), sum() like this.

Posted: Wed Nov 05, 2003 10:53 am
by Weirdan
Code: Select all
select * from table having max(to_days(date))=to_days(date)
It will give you expected results.