Jump to content

Order by and group


petenaylor

Recommended Posts

Hi all

 

I have a table which is attached that has prices and a product_id. What I need to do is firstly, order by the price and then group by the product_id.

 

I need to know how to write the mySQL query to do this. I can only group by and then sort by.

 

Many thanks for your help.

 

Pete

post-73756-13482403723849_thumb.jpg

Link to comment
Share on other sites

Hi there

 

Thanks for your help so far!

 

Basically, I need to get my product IDs in order of price. So that I can query the database again to get the product information.

 

If you look at my database, you can see that the prices can be sorted by value ascending. I need to then group the product IDs in the correct order so I can then query the database again for the full information.

 

Many thanks

 

Pete

Link to comment
Share on other sites

This sounds like you are going to be looping through the results of one query and performing further queries within loop. This is not a good design decision. Get the results you need first time, then process the results.

 

Which brings me back to my original question - what exactly is the final result that you want to achieve? From the data you gave us how do expect the final output to look?

Link to comment
Share on other sites

Hi there

 

I have restructured the database to have the 5 prices in the same table as the rest of the data.

 

Is there anyway I can search multiple rows for the lowest value across the 5 columns and then show the results in this order?

 

I have attached my database.

 

Regards

Pete

post-73756-1348240372483_thumb.jpg

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.