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

  • SEARCH
  • Home
  • 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 3430548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:13:04+00:00 2026-05-18T07:13:04+00:00

Having a bit of trouble dealing with not exist clause in a query. I

  • 0

Having a bit of trouble dealing with not exist clause in a query.

I have three tables:

Meal

no_meal integer
type_meal varchar(255)

Consumed

no_meal integer
designation varchar(255)
quantity integer

Food

designation varchar(255)
quantity integer
type varchar(255)

Quantity in food is quantity stored and quantity in consumed is consumed quantity so, they will differ and thus natural inner join won’t cut it.

  • Type of food can be ‘drink’ ‘meat’ ‘fish’ and so on.
  • Type of meal can be ‘Breakfast’ ‘Lunch’ ‘Dinner’

I want a query that will tell me the drinks that have been consumed in all types of meals.

I’ve been toggling and testing code but can’t get it right. At the moment I’m trying this:

SELECT Consumed.designation
FROM Consumed
WHERE NOT EXISTS

(SELECT type_meal
 FROM Consumed, Food, Meal
 WHERE Consumed.designation = Food.designation
 AND Consumed.no_meal = Meal.no_meal
 AND type = 'Drink'
 ORDER BY Food.designation)

EXCEPT

(SELECT type_meal
 FROM Meal);

How the hell do I get it right?

Thanks for input.

EDIT:

I’ll add some data in order to make it clearer.

Food

Steak   100    Meat
Water   200    Drink
Coca cola    300   Drink

Meal

0001     Breakfast
0002     Lunch
0003     Dinner

Consumed

0001     Water       50
0002     Steak       20
0001     Coca cola   20
0003     Water        5
0002     Water       15

Now, I want to know which drink has been consumed in every meal, which will only give water.

Hope I cleared some minds about the problem

  • 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-18T07:13:05+00:00Added an answer on May 18, 2026 at 7:13 am

    Twist your mind a little bit, and think with double negatives ….

    I want […] the drinks that have been consumed in all types of meals.

    You want all drinks for which there are NO meal types for which that drink is NOT part of the meal type:

    select distinct f.designation 
    from food f 
    where 
      type = 'Drink' and 
      not exists (
        select * 
        from meal m1
        where not exists (
          select *  
          from meal m2
          join consumed c on c.no_meal = m2.no_meal
          where 
            m1.no_meal = m2.no_meal and
            c.designation = f.designation
        )
      ) 
    

    This is called relational division.

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

Sidebar

Related Questions

i'm having a bit of trouble trying to write an sql query. i have
Having a bit of trouble using the List.Find with a custom predicate i have
I'm having a bit of trouble loading pages into an already-existing colorbox. I have
I'm having a bit of trouble figuring out exactly why my report will not
I'm having a bit trouble with a query in Linq to Entities which I
having a bit of trouble adding some data to a database. I have the
having a bit of trouble with replacing things that are NOT 0-9A-Za-z[:space] because I
I'm having a bit of trouble getting the right results from a query. At
I'm having a bit of trouble doing some unit-testing using moq. If I have
Having a bit of trouble with htaccess, at the moment I have a rewrite

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.