简体   繁体   中英

LEFT JOIN of two tables

I have two lists Tender and Tender Items. Tender list contains column 'Tender Name', 'Tender Description'. Second list Tender Items contains columns 'Item Name', 'Item Price' and a lookup column 'Tender Name' from 1st list Tender.

There may be that A Tender contains any items or not. So I want to get the left join of these two lists so that I can get each Tender with items if any. Below is the join of two lists that I want to achieve.

First list Tender contains 3 tenders. and second list Tender items contain 2 items. Below is the left join of the two lists where "tender 3" has no item:

  Tender Name, Tender Description, Item Name, Item Price.

  tender 1,tender desc1, item1, 500

  tender 2, tender desc2,item2, 400

  tender 3,tender desc3,NULL,NULL

How can I achieve this above result?

SELECT T.TENDERNAME, T.TENDERDESC, TI.ITEMNAME, TI.ITEMPRICE
FROM TENDERS T LEFT JOIN TENDERITEMS TI
ON T.TENDERNAME = TI.TENDERNAME

You would be better off defining an integral key for Tenders and then using that value as a foreign key in TenderItems. If you change the tender name, the link between the tender and its items would be lost.

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