Jump to content

[SOLVED] Me again!! Query Help Please.


d_barszczak

Recommended Posts

Hi all,

 

Just when im getting to grips with this mysql business i have another problem ???

 

The following query works:

SELECT MAX(`order`) as `MAXorder` FROM `nav_directory`;

 

which return MAXorder = 10.

 

i would like it to return the tag also

tag, MAXorder

page1, 10

 

My Solution to this was:

SELECT `tag`, MAX(`order`) as `MAXorder` FROM `nav_directory` GROUP BY order;

 

But that lists all the tags. Can anyone help???

Link to comment
Share on other sites

The robust way to do this is as follows (untested):

 

SELECT n.tag, n.order
FROM nav_directory AS n
JOIN 
( SELECT MAX(order) as MAXorder FROM nav_directory ) AS sub ON ( sub.MAXorder = n.order )

Of course, you could add as many conditions as you wanted.  Don't forget about the boundary case; you may want an order by, too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.