gisvpn
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
»bp
ASKER