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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:29:53+00:00 2026-06-04T06:29:53+00:00

What I have is a mySQL query that will select some drinks and return

  • 0

What I have is a mySQL query that will select some drinks and return basic information about the drink, as well as a list of the ingredients of that particular drink, as well as the rating for the particular drink. I have 3 tables drinks, drinks_ratings, drinks_ing

So, my issue is that say I want to get information about drinks that contain vodka, and are in a highball glass I would run the query below…

It works, its just my issue is that it doesnt return ALL the ingredients back. For Example, if I return “randomDrinkName1” and it happened to have vodka and soda in it….when i get the information back it leaves out the soda because i said WHERE ing = voda, so I understand why this is happeneing…but Is there some other type of WHERE clause I can do to check if it has “vodka” and return it along with all the other ingredient information that might also be there?

I know I could just do a query before this query that gets be back ids that have vodka in them from my drinks_ing table.

But this seems like it could be bad idea …like if there were 1000s of drinks with vodka in them just to do a query on a select with a 1000 OR statements.

I’m interested if there is a way i can easily do this all in one query. thanks!

select dIngs.id,
    dIngs.name,
    dIngs.descrip,
    dIngs.type,
    dIngs.ing,
    AVG(b.rating) as arating,
    COUNT(b.id) as tvotes
from (
    select a.id,
        a.name,
        a.descrip,
        a.type,
        concat (
            '[',
            GROUP_CONCAT('{\"ing\":', c.ing, ',\"parts\":', c.parts, '}'),
            ']'
            ) ing
    from drinks a
    left join drinks_ing c on a.id = c.did
    where c.ing = "vodka"
        and a.type = "highball"
    group by a.id
    ) dIngs
left join drinks_ratings b on dIngs.id = b.id
group by dIngs.id
order by arating desc,
    tvotes desc LIMIT 0,
    50;

edit:
to illustrate a result that I would want to get is like this:

           [0]
              descrip = "the description text will be here"
              arating = 0
              id = 4
              ing = [ {"ing": "vodka", "parts": 4}, {"ing": "soda", "parts": 2}, {"ing": "sprite", "parts": 2} ]
              name = "awesomeDrink"
              type = "highball"
              tvotes = 0

but what im actually getting back just includes the vodka ing because thats what i was checking for

           [0]
              descrip = "the description text will be here"
              arating = 0
              id = 4
              ing = [ {"ing": "vodka", "parts": 4} ]
              name = "awesomeDrink"
              type = "highball"
              tvotes = 0

To be clear, if i dont supply something like where ing = vodka, i get all the ingredients back just fine. thats not the issue….

I need it to just check if one of the potential ingredients happens to be vodka, then basically return all the ing data…and if vodka isn’t a potential ingredient, ignore that drink and NOT return it.

edit:
what my tables look like..

drinks_ing
---------------
did (which is the drink id its associated with)
id (the id of the ingredient aka "vodka")
parts

drinks
---------------
id
name
description
type
timestamp

drinks_ratings
-----------------
id
userid
rating
timestamp
  • 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-04T06:29:54+00:00Added an answer on June 4, 2026 at 6:29 am

    Your best approach may be to use a self join. This is where you reference the same table twice, but by different names. Roughly this would look like:

    SELECT     d.stuff
    FROM       drinks d
    INNER JOIN drinks v on d.id = v.id
    WHERE      v.ingredient = "vodka"
    

    Update: Making this better correspond to the tables in question. This is saying: given all of the vodka ingredients, find all of the ingredients that are found in the same drink as that vodka ingredient.

    SELECT     d.*
    FROM       drinks_ing d
    INNER JOIN drinks_ing v on d.did = v.did
    WHERE      v.ing = "vodka"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have a mysql query that gets some data. Then runs another
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have a MySQL query which gets including some vars like that: messages TABLE
I have a mysql query that shows the users last viewed documents. Some sort
I have a mysql query that targets a single column in a single row
I have a MySQL query that: gets data from three tables linked by unique
I have a mysql query that uses union to join multiple queries into one
I have a mysql db query that I'd like to take and condense into
I have a PHP/MySQL query that returns to an HTML table, and I'm stuck
So I have this awesome MySQL query that's returning me an awesome array >

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.