Home > other >  Joining multiple tables ORACLE
Joining multiple tables ORACLE

Time:03-08

SELECT *
FROM STORE
     ,MATERIAL
     ,STOREBIN
     ,VENDOR
     ,MATERIALPRICE
     ,SD
WHERE STOREBIN.STOREBINID( ) = SD.STOREBINID
AND SD.VENDORID = VENDOR.VENDORID( )
AND MATERIAL.MATERIALID = MATERIALPRICE.MATERIALID( )
AND STORE.STOREID = SD.STOREID

I have this simple query here, but i want to change the ( ) notations into joins, how would this be possible? I was thinking:

RIGHT JOIN SD ON STOREBIN.STOREBINID = SD.STOREBINID
LEFT JOIN VENDOR ON VENDOR.VENDORID = SD.VENDORID
LEFT JOIN MATERIALPRICE ON MATERIALPRICE.MATERIAID = MATERIAL.MATERIALID
WHERE STORE.STOREID = SD.STOREID

But that hardly seems right because i need to join each table onto different tables.

CodePudding user response:

This would be equivalent (if we also add the additional criteria you mentioned):

FROM 
    SD 
    
    INNER JOIN STORE as S
    on S.STOREID = SD.STOREID

    INNER JOIN MATERIAL as M
    ON M.MATERIALID = SD.MATERIALID

    LEFT JOIN STOREBIN as SB
    ON SB.STOREBINID = SD.STOREBINID

    LEFT JOIN VENDOR as V
    ON V.VENDORID = SD.VENDORID

    LEFT JOIN MATERIALPRICE as MP
    ON MP.MATERIALID = M.MATERIALID

  • Related