Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:23:40+00:00 2026-05-29T21:23:40+00:00

I have 3 tables with this structure: Recipe id | recipe_name Ingredients id |

  • 0

I have 3 tables with this structure:

Recipe

id | recipe_name

Ingredients

id | ingredients_name

Relationship

rid | recipe_id | ingredients_id

Example i search for recipe’s with an ingredient of “chicken” and “mayonnaise” then it will display all the recipe’s having this two ingredients. i already get the code for that:

SELECT * from recipe r
INNER JOIN relationship ri on r.id=ri.recipe_id
INNER JOIN ingredients i on i.id=ri.ingredients_id
WHERE i.ingredients_name IN ('chicken','mayonnaise')
GROUP BY r.id

But what I want is that when a recipe contains only chicken and mayonnaise as its ingredients, it must display on a separate result. How can i do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:23:42+00:00Added an answer on May 29, 2026 at 9:23 pm

    By adding a HAVING clause – like so:

    SELECT * from recipe r
    INNER JOIN relationship ri on r.id=ri.recipe_id
    INNER JOIN ingredients i on i.id=ri.ingredients_id
    GROUP BY r.id
    HAVING COUNT(DISTINCT i.ingredients_name)=2 AND
           COUNT(DISTINCT case when i.ingredients_name IN ('chicken','mayonnaise') 
                               then i.ingredients_name end)=2
    

    (Note: this will return recipes that only include both chicken and mayonnaise, and no other ingredients. To return recipes that include both chicken and mayonnaise, but that could also include other ingredients, remove the COUNT(DISTINCT case condition and reinstate the WHERE clause.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
In report design, I have 2 tables (Current and Proposed) the structure like this:
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables on MySQL, with this structure: Users: id | name Accounts:
What is the best way to setup this table structure. I have 3 tables,
I have 4 tables with the same structure. This 4 tables are generated from
I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table structure and would like to map it using Fluent Hibernate
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.