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 8380475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:28:04+00:00 2026-06-09T16:28:04+00:00

I have a SQL query that has me stumped. Basically, I have a Recipes

  • 0

I have a SQL query that has me stumped. Basically, I have a Recipes table that contains (as you’ve no doubt guessed,) many recipes. I have an Ingredients table which contains all sorts of ingredients. I have a RecipeIngredients table that links a recipe to what ingredients it uses. Lastly, I have a PopularIngredients table (it’s actually a view, but who cares?) that contains the most popular ingredients people might have in their kitchen:

CREATE Table Recipes
(
  RecipeId int4,
  Title varchar(100)
);

CREATE Table Ingredients
(
  IngredientId int4,
  Name varchar(100)
);

CREATE Table RecipeIngredients
(
  RecipeId int4,
  IngredientId int4,
  Amount int2
);

CREATE Table PopularIngredients
(
  IngredientId int4
);

My goal is to get a list of all recipes that use only popular ingredients.

A SQL Fiddle with sample data can be found here.

What I’m looking for is a query that will return Chicken Salad and Pancakes. Aligator Burgers would not be returned, since it uses aligator which is not a popular ingredient.

I’ve tried a few things involving sub-selects and the ALL keyword, but haven’t had any luck. I’ve tried various inner and outer joins, but Recipe rows will still show up as long as at least one of its ingredients is popular. Any help would be much appreciated!

I’m using Postgres 9.1.

  • 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-06-09T16:28:06+00:00Added an answer on June 9, 2026 at 4:28 pm

    This gets all recipes which have no ingredients that are not in the PopularIngredients table.

    select * from Recipes r where not exists (
      select * from RecipeIngredients ri 
      left join PopularIngredients pi on pi.IngredientId=ri.IngredientId
      where ri.RecipeId=r.RecipeId and pi.IngredientId is null
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Project that has many Tasks. I have a SQL query that
Suppose I have a SQL Query that isn't really nice. The SQL Query has
Scenario I'm using SQL Server 2005 I have a T-Sql query that has multiple
i have an sql query that has one unnamed column as a list of
I have a linq-to-sql query that I use to fill an object that has
I have a SQL table AddressCount that has 3 fields: address , state ,
I have a SQL query that has 3 int columns, and then 3 Rank()
I have a SQL query that has 4 UNIONS and 4 LEFT JOINS. It
I have created a DataTable that I fill using a SQL query that has
I have a complex query that includes some dynamic sql which partially depends upon

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.