简体   繁体   中英

Joining Two table with three ON

im trying to slect data from two tables with out primary key now my question is what im doing wrong in my joning ,can i use more than 1 ON in joining table.

SELECT 
    A.PRODUCT, 
   A.WSTYPE, A.PACKAGE, AWACSLF.LFSIZE,AWACSLF.DEFAULTWOQTY
FROM OCAPSYS.AWACSRECIPEBYWSTYPE A
 inner join  OCAPSYS.AWACSLF 
 On A.LEADFRAME12NC = AWACSLF.LF12NC  
 On A.PRODUCT =  AWACSLF.DEVICE
 On A.PACKAGE =  AWACSLF.PACKAGE

The proper syntax is to use AND :

   SELECT 
       A.PRODUCT, 
       A.WSTYPE, A.PACKAGE, AWACSLF.LFSIZE,AWACSLF.DEFAULTWOQTY
       FROM OCAPSYS.AWACSRECIPEBYWSTYPE A
       INNER JOIN  OCAPSYS.AWACSLF 
       ON A.LEADFRAME12NC = AWACSLF.LF12NC  
       AND A.PRODUCT =  AWACSLF.DEVICE
       AND A.PACKAGE =  AWACSLF.PACKAGE

You can add multiple ON as long as the data of each tables doesn't have the same column name. But ON is only use for tables only. For example:

SELECT O.OrderNumber, CONVERT(date,O.OrderDate) AS Date, 
       P.ProductName, I.Quantity, I.UnitPrice 
  FROM [Order] O 
  JOIN OrderItem I ON O.Id = I.OrderId 
  JOIN Product P ON P.Id = I.ProductId
ORDER BY O.OrderNumber

What are you really aiming to do about the data? To make it array of an array? Or just array?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM