gabeg Posted May 30, 2007 Share Posted May 30, 2007 I have two tables, one is called menuitem, and has columns id, category, name, description. Then I have a table called menuprice, with columns menu_id, size, price. Say I have menu item called pizza with id 2, I want to select all the rows from menuprice that match menu_id = 2. I can make the call to show all the in from the menu item table, but is there is there someway I can display the price for each different size /price without making tons of sub_queries? When there begins to be a lot of menu items, querying the database for each item adds up Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/ Share on other sites More sharing options...
btherl Posted May 30, 2007 Share Posted May 30, 2007 Are you looking for this: SELECT * FROM menuitem JOIN menuprice ON (menuitem.id = menuprice.menu_id) That will give you duplicate rows for an item when there are different sizes, so you can no longer assume each item is listed once, which you probably could when you queried from menuitem only. Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-264494 Share on other sites More sharing options...
gabeg Posted May 30, 2007 Author Share Posted May 30, 2007 Are you looking for this: SELECT * FROM menuitem JOIN menuprice ON (menuitem.id = menuprice.menu_id) That will give you duplicate rows for an item when there are different sizes, so you can no longer assume each item is listed once, which you probably could when you queried from menuitem only. Yeah I know I can do that, but the duplicate rows kills what I'm trying to do Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-264852 Share on other sites More sharing options...
bubblegum.anarchy Posted May 31, 2007 Share Posted May 31, 2007 Use DISTINCT or GROUP BY to remove the duplicates. Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-265380 Share on other sites More sharing options...
fenway Posted May 31, 2007 Share Posted May 31, 2007 Use DISTINCT or GROUP BY to remove the duplicates. Definitely group by, DISTINCT is the most useless modifier I've ever come across (except inside a COUNT() ). Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-265522 Share on other sites More sharing options...
bubblegum.anarchy Posted June 1, 2007 Share Posted June 1, 2007 Use DISTINCT or GROUP BY to remove the duplicates. Definitely group by, DISTINCT is the most useless modifier I've ever come across (except inside a COUNT() ). or GROUP_CONCAT Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-266103 Share on other sites More sharing options...
fenway Posted June 1, 2007 Share Posted June 1, 2007 Use DISTINCT or GROUP BY to remove the duplicates. Definitely group by, DISTINCT is the most useless modifier I've ever come across (except inside a COUNT() ). or GROUP_CONCAT Useless? Or did you mean something else? Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-266258 Share on other sites More sharing options...
bubblegum.anarchy Posted June 1, 2007 Share Posted June 1, 2007 no no... DISTINCT is also useful in a GROUP_CONCAT Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-266581 Share on other sites More sharing options...
fenway Posted June 2, 2007 Share Posted June 2, 2007 no no... DISTINCT is also useful in a GROUP_CONCAT Ah, right... of course, my bad. Quote Link to comment https://forums.phpfreaks.com/topic/53512-looking-for-the-most-efficient-way-to-do-this/#findComment-266634 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.