how to get max date from database table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
qumar
Forum Commoner
Posts: 29
Joined: Wed Nov 01, 2006 8:20 am

how to get max date from database table

Post by qumar »

pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi,
please give some idea how to get max picture. i am uploading images under event id. each event id has more dates. i want display the max date image under event id. give some idea. i am using following query.

[syntax="php"]<?php
$result = mysql_query("SELECT * FROM maaking_pictures WHERE event_id=$event_id ORDER BY picture_id DESC limit $nexlimit,$users_per_page");
?>
thanks,
qumar.


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
mezise
Forum Newbie
Posts: 17
Joined: Tue Sep 18, 2007 4:38 am

Post by mezise »

Hi,
you are not very specific about the problem. If I get it right you have a table maaking_pictures with event_id field and e.g. date_of_picture field. If you want to select last picture during given event you may use a query like this:

Code: Select all

SELECT * FROM `maaking_pictures`
WHERE `event_id` = [$event_id]
ORDER BY `date_of_picture` DESC
LIMIT 1;
Michal
Last edited by mezise on Tue Sep 18, 2007 11:22 am, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

The MySQL function MAX() might be quicker.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mezise
Forum Newbie
Posts: 17
Joined: Tue Sep 18, 2007 4:38 am

Post by mezise »

Or not...
Post Reply