-2
我有兩個表,quotation
和comparitive
。加入兩個表並顯示只有特定條件的記錄
表quotation
具有字段:tender_id, supplier_name
表comparitive
具有字段:tender_id, sup_name,make,shelf_life,datasheet,coc
現在我想的是,我需要它連接這兩個表並顯示記錄,其中quotation.tender_id=comparitive.tender_id and comparitive.tender_id=$tender_id and comparitive.sup_name IN quotation.supplier_name
查詢。
我該如何做到這一點?我嘗試過不同的方式,但期望的輸出不會到來。
這是我試過的。
SELECT comparitive_statement1.sup_name
, comparitive_statement1.tender_id
, comparitive_statement1.coc
, comparitive_statement1.shelf_life
, comparitive_statement1.make
, comparitive_statement1.datasheet
, quotation_items.supplier_name
, quotation_items.tender_id
FROM comparitive_statement1
, quotation_items
WHERE comparitive_statement1.tender_id = quotation_items.tender_id
AND quotation_items.tender_id='$tender_id'
and quotation_items.supplier_name = comparitive_statement1.sup_name
group by quotation_items.supplier_name
向我們展示您嘗試過的。 – Epodax
我已經添加了我所嘗試過的。 –
使用內部聯接您可以訪問期望的數據[link](http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/) – PRANAV