Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL nested query

Status
Not open for further replies.

lmbylsma

Programmer
Nov 11, 2003
33
US
I have this line of code:

$prelimResult = mysql_query("SELECT MAX(volume),MAX(issue),MAX(year) FROM articles",$db);

That doesn't work quite how I want it to. I want it to find the largest volume, then the largest issue within that volume but instead this finds the largest volume and largest issue. So say the latest issue is Volume 2, Issue 1, but there exists a Volume 1, Issue 2, it will think the latest issue is Volume 2, Issue 2 which doesn't exist.

I know I need to make some sort of nested query, but I don't know the proper syntax?
 
Maybe should try this way.
Code:
SELECT  MAX(volume),MAX(issue) FROM articles WHERE issue  in (SELECT MAX(issue) FROM articles)

________
George, M
 
select max(volume),issue from articles order by issue desc;


the result will always be one record anyway since you don't have a group by.


ps shaddow I don't think you're query will come with the desired result since select max(issue) from articles has no connection with the volume



 
Yes you're right, but i never tought at a simple solution :)

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top