Link to home
Start Free TrialLog in
Avatar of gisvpn
gisvpnFlag for United States of America

asked on

SQL Statement - select MAX?

SQL Statement,

I am having a problem with this SQL statement (I think it is an easy fix!) but I just cannot get it right.

SELECT ppm_name, ppm_id FROM main WHERE ppm_user_link='$UID' and ppm_id=MAX(ppm_id)

I would like to select the columns 'ppm_name' and 'ppm_id' from the 'main' table where it matches the 'UID' and it is the highest 'ppm_id' << I think this is where the error is.. with the MAX(ppm_id)?

How can I select these columns from the table where it is the highest ppm_id and ppm_user_link matches the $UID variable?

THanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gisvpn

ASKER

Great! worked. Could I ask so m1 and m2 allow you to give the different queries aliases? I think I can work out what it is doing if that is right
Avatar of Bill Prew
Bill Prew

Yes, since we are nesting queries against the same table we use aliases to remove any confusion about which table we are referencing a column from.


»bp