help needed with SELECt and max value

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

help needed with SELECt and max value

Post by pelegk2 »

is there any way to ask for a max number :

Code: Select all

select distinct max(round_num),del_id from delivery where region_id=018 group by round_num
in this case i recive 2 max(round_num) (1 and 2 ) for the "where region_id=018 "
how can i make it so i will gt only the 1 that is realy maximux?
thnaks in advance
peleg
User avatar
pedrokas
Forum Commoner
Posts: 32
Joined: Thu Jan 15, 2004 10:53 am
Location: Lisboa, Portugal

Post by pedrokas »

u don't need the distinct!
this way u get the max value from the table for every iqual round_num

Code: Select all

select max(round_num),del_id from delivery where region_id=018 group by round_num
if u want only the row with the max the query must be simple

Code: Select all

select max(round_num) from delivery
[mysql_man]if u need to know more than the max , u must do the query with the group by (its imperative) and with that u get the max for every distinct row in the group by...[/mysql_man]
Post Reply