sql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

sql query

Post 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)

:oops:
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

LOL,
u rae right... there is no max date is there?!
i meant the recent one of course...
Thanks..
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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. ;)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

select * from table having max(to_days(date))=to_days(date)
It will give you expected results.
Post Reply