-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