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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:14+00:00 2026-05-26T18:33:14+00:00

I have two tables that look like this: Supplier SN SNAME Stat City +———-+——-+—-+——–+

  • 0

I have two tables that look like this:

Supplier

  SN         SNAME  Stat   City
+----------+-------+----+--------+
| S1       | Smith | 20 | London |
| S2       | Jones | 10 | Paris  |
| S3       | Blake | 30 | Paris  |
| S4       | Clark | 20 | London |
| S5       | Adams | 30 | Athens |
+----------+-------+----+--------+

Shipment

 SN    PN   QTY
+----+----+-----+
| S1 | P1 | 300 |
| S1 | P2 | 200 |
| S1 | P3 | 400 |
| S1 | P4 | 200 |
| S1 | P5 | 100 |
| S1 | P6 | 100 |
| S2 | P1 | 300 |
| S2 | P2 | 400 |
| S3 | P2 | 200 |
| S4 | P2 | 200 |
| S4 | P4 | 300 |
| S4 | P5 | 400 |
+----+----+-----+

I have the find the following:

List the supplier names (SNAME) for those suppliers who ship at least all those parts (PN) supplied by supplier S2.

In other words, I need to list all those suppliers who ship at least P1 and P2, although obviously my query needs to be focused more on the question at hand.

I’m pretty sure I have to use some form of NOT EXISTS — perhaps the double not exists, to achieve this. I tried doing a self-join of the Shipment table to itself — but I can’t understand how to get it beyond checking for ANY item that appears in the PN for S2 and instead check to make sure ALL parts for S2 are in the list before including the name in the result.

  • 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-26T18:33:15+00:00Added an answer on May 26, 2026 at 6:33 pm

    I used a Common Table Expression to accomplish this:

    --CTE will contain records from the Supplier you are looking to check against
    WITH desiredSN AS
    (
       SELECT s.SN, s.PN 
       FROM Shipment AS s
       WHERE s.SN = 'S2'
    )
    --SELECT will join all other shippers with each record of your Supplier S2 here
    SELECT s.SN
    FROM Shipment AS s
    INNER JOIN desiredSN AS d ON s.PN = d.PN
    WHERE s.SN != 'S2'
    GROUP BY s.SN
    --Having ensures that the count of your old supplier matches
    --the number a potential supplier overlaps with
    HAVING COUNT(1) =
    (
       SELECT COUNT(1)
       FROM desiredSN AS d
    )
    

    If you do not want to use the CTE, you can use subqueries instead:

    SELECT s.SN
    FROM Shipment AS s
    INNER JOIN 
    (
       SELECT s.SN, s.PN
       FROM Shipment AS s
       WHERE s.SN = 'S2'
    )
    AS d ON s.PN = d.PN
    WHERE s.SN != 'S2'
    GROUP BY s.SN
    HAVING COUNT(1) =
    (
       SELECT COUNT(1)
       FROM Shipment AS s
       WHERE s.SN = 'S2'
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables that look like this: TH TH TH TH
I have two tables in my database that look like that: Customer: C_ID city
I currently have two tables that look something like this: Table 1 Id |
I have two tables that look a little like this AGR_TERR_DEF_TERRS ID DEF_ID TERRITORY_ID
I have two tables in a teradata database that look like this accounts account_number
I have two tables that look like this: Table: cases id name status case_no
I have two tables that look like this: Products: id category name description active
I have a two tables that look like this (this is an example of
so I have this problem. My Database has two tables that look something like
I have two tables that look something like this: Checkpoint with field: Checkpoint_id Checkpoint_name

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.