Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Not sure about the validity of the query

I would like to write an sql join query which retrieves the product number and supplier numbers of all unique pairs of suppliers who supply the same product, along with their product purchase prices.

Columns are:

SUPPLIER (SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PRODUCT (PRODNR, PRODNAME, PRODTYPE, AVAILABLE_QUANTITY)

SUPPLIES (SUPNR, PRODNR, PURCHASE_PRICE, DELIV_PERIOD)

PURCHASE_ORDER (PONR, PODATE, SUPNR)

PO_LINE (PONR*,* PRODNR, QUANTITY)

NOTE: (primary keys are BOLD, foreign keys are bold in italics

my code is:

SELECT S1.SUPNR, S2.SUPNR, S2.PRODNR, S2.PURCHASE_PRICE
FROM SUPPLIES S1, SUPPLIES S2
WHERE S1.SUPNR > S2.SUPNR

Is it a correct query?

>Solution :

I guess you just need to add PRODNR

 SELECT S1.SUPNR, S2.SUPNR, S2.PRODNR, 
  S2.PURCHASE_PRICE
  FROM SUPPLIES S1 join SUPPLIES S2
  On S1.SUPNR > S2.SUPNR and
  S1.Prodnr=s2.prodnr
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading