Jump to content


Photo

*SOLVED* ignoring non-unique results on SELECT statements


  • Please log in to reply
2 replies to this topic

#1 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 21 August 2006 - 10:16 PM

when i do the following SELECT statement it's possible for the recipe to be returned multiple times if an ingredient applies more than once...such as a search on "garlic" that may return on "garlic", "garlic cloves", "garlic salt" etc.  How can i limit the select so it only returns one instance of the recipe even on multiple ingredient matches?

SELECT
   recipes.name,
   recipes.description
FROM
   recipes, recipe_ingredients
WHERE
   recipe_ingredients.recipe_id=recipes.id
AND MATCH(ingredient) AGAINST ("'.strtolower($_GET['ingredient']).'" IN BOOLEAN MODE)
ORDER BY name ASC


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 11:38 PM

Add a "GROUP BY recipes.id"
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 21 August 2006 - 11:43 PM

awesome!  thank you...i didn't even think to look at the GROUP BY function as I was making my way through the function list.  Cheers!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users