ldsmike88 Posted March 26, 2006 Share Posted March 26, 2006 I have a MySQL database with a whole lot of products in it. Each product has it's own row. Each product has a make, model, year, description etc. There are over 20 products with the same make but I need to query the database and display each make only once. Anyone know how to do this? Thanks!Mike Quote Link to comment Share on other sites More sharing options...
toplay Posted March 26, 2006 Share Posted March 26, 2006 Look into the use of "group by" clause or "distinct".[a href=\"http://dev.mysql.com/doc/refman/4.1/en/group-by-modifiers.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/gro...-modifiers.html[/a][a href=\"http://dev.mysql.com/doc/refman/4.1/en/distinct-optimization.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/dis...timization.html[/a]You also want to add the "order by" clause to have it sorted by what you want (make). Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted March 27, 2006 Author Share Posted March 27, 2006 AWESOME! The GROUP BY worked perfect. Now I have one more question. Some of my products are compatible with multiple makes, such as the Chevy Silverado and the GMC Sierra. Most of their parts can fit the either truck. So in this case I set the make to "Chevorlet, GMC" istead of having two different rows for the same product and my query says WHERE make LIKE '%Chevorlet%'. With the Chevorlet and GMC products when I run the GROUP BY query it looks like this:AudiBuickCadillacChevorletChevorlet, GMCChryslerChyslerFordGMCHondaIs there a way I can get everything inbetween the commas or everything before and after a comma and then erase the comma? Thanks! And thanks again toplay for the GROUP BY documentation. Quote Link to comment 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.