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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:49:01+00:00 2026-06-17T09:49:01+00:00

I have a simple application that tracks diners and their favorite flavors and desserts.

  • 0

I have a simple application that tracks diners and their favorite flavors and desserts. The records table is just the diner’s name and ID, the mid table tracks the desserts and flavors (again by an ID linked to another table of values).

CREATE TABLE IF NOT EXISTS `records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


INSERT INTO `records` (`id`, `name`) VALUES
(1, 'Jimmy Jones'),
(2, 'William Henry');


CREATE TABLE IF NOT EXISTS `mid` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `diner` int(11) NOT NULL,
  `dessert` int(11) NOT NULL DEFAULT '0',
  `flavor` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;


INSERT INTO `mid` (`id`, `diner`, `dessert`, `flavor`) VALUES
(1, 1, 3, 0),
(2, 1, 2, 0),
(3, 1, 15, 0),
(4, 1, 0, 1),
(5, 2, 3, 0),
(6, 2, 6, 0),
(7, 2, 0, 4),
(8, 1, 34, 0),
(9, 2, 0, 4),
(10, 2, 0, 22);

I’m a little stumped by what should be a simple query– I want to get all IDs from the records table where certain dessert or flavor requirements are met:

SELECT a.id 
FROM records AS a
JOIN mid AS b ON a.id = b.diner
WHERE b.dessert IN (3,2,6)
AND b.flavor IN (4,22)

This query returns no rows, even though there are records that match the where clauses. I am pretty sure I’m missing something obvious with the JOIN but I’ve tried INNER, OUTER, LEFT and RIGHT with no success.

Can someone put me on the right track and explain what I’m missing?

Thanks

  • 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-17T09:49:03+00:00Added an answer on June 17, 2026 at 9:49 am

    You seem to want diners that have the combinations. Here is one way:

    select diner
    from records
    group by diner
    having max(b.dessert = 3) = 1 and
           max(b.dessert = 2) = 1 and
           max(b.dessert = 6) = 1 and
           max(b.flavor = 4) = 1 and
           max(b.flavor = 22) = 1
    

    This answers your comment:

    select diner
    from records
    group by diner
    having max(case when b.dessert in (2, 3, 6) then 1 esle 0 end) = 1 and
           max(case when b.dessert in (4, 22) then 1 else 0 end) = 1
    

    If you are just looking for the records in a that match the conditions, use:

    select r.*, d.name
    from records r join
         diner d
         on r.diner = d.id
    where b.dessert IN (3,2,6) AND b.flavor IN (4,22)
    

    If this is what you want, the join condition in your query is wrong (a.id should be a.diner).

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

Sidebar

Related Questions

I have a simple application that loads an unmanaged dll and passes a few
I have a simple c++ application that generates reports on the back end of
I have a simple WPF application that uses ClickOnce to handle installing. Within this
I have a simple iPhone application that is very similar to the Page Control
I have a simple Android application that uses a JAR I have built. When
I have a simple test application (C# console application) that does an HTTP GET
I have a simple Desktop Facebook application that allows the user to retrieve some
I have a simple Swing Java application that performs searches, and the results are
I have got a Wavecom Supreme GSM modem. I wrote a simple application that
enter code here Hi All, I have a simple windows service application that connects

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.