Jump to content
Sign in to follow this  

Query table, sort by lower number of the two located in different colums

Recommended Posts

OK, the title is bit confusing. Lets say that I have a table with three columns (name, no1, no2) with following rows: (Mike, 5, 7), (Julie, 6, 2) and (Jack, 8, 3). Is there a query that will allow me to sort the results in such way that it will sort them by the lowest number from either no1 or no2, depending on which one is the lowest? So, the query would look at no1 and no2 and pick only the lowest one, do the same for rest of the rows and then order them by lowest resulting numbers? So the results should be:


(Julie, 6, 2)

(Jack, 8, 3)

(Mike, 5, 7)



Share this post

Link to post
Share on other sites

This assumes you're using MySQL

Edited by iarp

Share this post

Link to post
Share on other sites

Join the conversation

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

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.

Sign in to follow this  

  • 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.