Jump to content

Recommended Posts

Hi, thanks for reading. Basically what I want to know is, I have a database full products, with their own ids, size is denoted within the id, and is appended to the end, so, 12345M 12345L, 12345XL etc., now not all products come in multiple sizes so they'd just be called 12345, but what i want to know is when display the results is there any way i can concatenate the products that have multiple sizes so instead of displaying them all, I just show say the smallest size? I thought there may be an SQL query that could help otherwise I'm not sure how I could do it because they're mixed in with other products that don't have multiple sizes.

 

Thank you for all your help.

Link to comment
https://forums.phpfreaks.com/topic/175192-returning-unique-results/
Share on other sites

Hi Dixsta,

 

You would need to perform a DISTINCT MySQL query with an ORDER BY.

 

Do you have some current query code you can post?  Otherwise the below example should show what you need to do:

 

SELECT DISTINCT product FROM table ORDER BY price LIMIT 1

 

Or you could use the MIN operator and do:

 

SELECT DISTINCT product, min(price) FROM table

 

Hope this helps.


SELECT * FROM product WHERE Type = '$type' ORDER BY Stock DESC $limit
// $limit is a variable used for pagination, $type just relates to a product of a certain type

 

I hope that's of some use to you and for example that may return products with the id:

 

12345S

12345M

12345L

12346

12347

12348L

12348XL

12349

12350M

12350XL

 

and i want to be left with say

 

12345S

12346

12347

12348L

12349

12350M

 

Thanks for the help.

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.