Dixsta Posted September 23, 2009 Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/ Share on other sites More sharing options...
Bricktop Posted September 23, 2009 Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/#findComment-923372 Share on other sites More sharing options...
Dixsta Posted September 23, 2009 Author Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/#findComment-923378 Share on other sites More sharing options...
Bricktop Posted September 23, 2009 Share Posted September 23, 2009 Hi Dixsta, What rows does the "product" table contain? i.e.: id size product description price etc. Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/#findComment-923385 Share on other sites More sharing options...
Dixsta Posted September 23, 2009 Author Share Posted September 23, 2009 Id, stock, name, type, notes, weight Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/#findComment-923392 Share on other sites More sharing options...
sasa Posted September 23, 2009 Share Posted September 23, 2009 try SELECT * FROM product WHERE Type = '$type' GROUP BY LEFT(Stock, 5) ORDER BY Stock DESC $limit Quote Link to comment https://forums.phpfreaks.com/topic/175192-returning-unique-results/#findComment-923421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.