Php 连接两个表并仅显示具有特定条件的记录
我有两个表,Php 连接两个表并仅显示具有特定条件的记录,php,mysql,Php,Mysql,我有两个表,quote和compariative 表quote包含以下字段:tender\u id、supplier\u name 表compariative包含以下字段:tender\u id、sup\u name、make、shelf\u life、datasheet、coc 现在我需要的是一个查询,它连接这两个表并显示记录,其中quote.tender\u id=comparitive.tender\u id和comparitive.tender\u id=$tender\u id和com
quote
和compariative
表quote
包含以下字段:tender\u id、supplier\u name
表compariative
包含以下字段:tender\u id、sup\u name、make、shelf\u life、datasheet、coc
现在我需要的是一个查询,它连接这两个表并显示记录,其中quote.tender\u id=comparitive.tender\u id和comparitive.tender\u id=$tender\u id和comparitive.sup\u name位于quote.supplier\u 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
这个查询应该可以工作。此外,在查询中使用
比较语句1.tender\u id
和quote\u项是没有意义的,因为它们将是相同的。向我们展示您尝试过的内容。我添加了我尝试过的内容。使用内部连接可以访问预期的数据[link](),结果有什么问题?向我们展示示例数据和预期结果。@PRANAV他实际上是在做一个内部联接,联接条件在where条件中。
SELECT cs.sup_name
, cs.tender_id
, cs.coc
, cs.shelf_life
, cs.make
, cs.datasheet
, q.supplier_name
FROM comparitive_statement1 cs
LEFT JOIN quatation_items q
ON cs.tender_id = q.tender_id
WHERE q.tender_id='$tender_id'
AND q.supplier_name = cs.sup_name
GROUP BY q.supplier_name