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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:41:15+00:00 2026-06-17T07:41:15+00:00

I have a table: custID orderID orderComponent ===================================== 1 123 pizza 1 123 wings

  • 0

I have a table:

custID    orderID    orderComponent
=====================================
1          123        pizza
1          123        wings
1          234        breadsticks
1          239        salad
2          456        pizza
2          890        salad

I have a list of values – pizza, wings, breadsticks, and salad. I need a way to just get a true/false value if a customer has at least one record containing each of these. Is that possible with a mysql query, or do I just have to do a select distinct(orderComponent) for each user and use php to check the results?

  • 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-17T07:41:16+00:00Added an answer on June 17, 2026 at 7:41 am

    If you are just looking to see if the customer has ordered all items, then you can use:

    select t1.custid,
      case when t2.total is not null 
        then 'true'
        else 'false'
      end OrderedAll
    from yourtable t1
    left join
    (
      select custid, count(distinct orderComponent) Total
      from yourtable
      where orderComponent in ('pizza', 'wings', 'breadsticks', 'salad')
      group by custid
      having count(distinct orderComponent) = 4
    ) t2
      on t1.custid = t2.custid
    

    See SQL Fiddle with Demo

    If you want to expand this out, to see if the custid has ordered all items in a single order, then you can use:

    select t1.custid,
      t1.orderid,
      case when t2.total is not null 
        then 'true'
        else 'false'
      end OrderedAll
    from yourtable t1
    left join
    (
      select custid, orderid, count(distinct orderComponent) Total
      from yourtable
      where orderComponent in ('pizza', 'wings', 'breadsticks', 'salad')
      group by custid, orderID
      having count(distinct orderComponent) = 4
    ) t2
      on t1.custid = t2.custid
      and t1.orderId = t2.orderid
    

    See SQL Fiddle with Demo

    If you only want the custid and the true/false value, then you can add distinct to the query.

    select distinct t1.custid,
      case when t2.total is not null 
        then 'true'
        else 'false'
      end OrderedAll
    from yourtable t1
    left join
    (
      select custid, count(distinct orderComponent) Total
      from yourtable
      where orderComponent in ('pizza', 'wings', 'breadsticks', 'salad')
      group by custid
      having count(distinct orderComponent) = 4
    ) t2
      on t1.custid = t2.custid
    

    See SQL Fiddle with Demo

    Or by custid and orderid:

    select distinct 
      t1.custid,
      t1.orderid,
      case when t2.total is not null 
        then 'true'
        else 'false'
      end OrderedAll
    from yourtable t1
    left join
    (
      select custid, orderid, count(distinct orderComponent) Total
      from yourtable
      where orderComponent in ('pizza', 'wings', 'breadsticks', 'salad')
      group by custid, orderID
      having count(distinct orderComponent) = 4
    ) t2
      on t1.custid = t2.custid
      and t1.orderId = t2.orderid
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

I have below sample format table structure: CUSTOMER table CUSTID INT,//PRIMARY KEY CUSTDATA VARCHAR
I have a sale table includes purchases/returns/exchanges Sample: --------**saleTbl**------------ CustID | DOP | SKU
I have a table CustPurchase (name, purchase) and another table CustID (id, name). I
Say we have customer table which has record CustId LastName 1 Hamlin In one
I have the following data in the table SALES: BillItemID CustID BillDate Item BillAmt
Ok so I have a table where we have custid, lastname, firstname, and DOB.
I have two tables Customer and Contract Table CustomerTable CustID(pk) CustName CompanyName ContractTable ContractID(pk)
I have a basic table named customer: CustId Name AB1 George Arkin AB2 Indiana
I have a table linking customers to previous purchases: RecID CustID ProdID 1 20
I have the following table custid ordid qty datesold 1 A2 12 2008-01-05 2

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.