合并结果表

时间:2018-05-03 14:21:02

标签: php mysql sql

如果model_name和model匹配,我将如何在联接表上合并结果?

表:tw

model
customer_name

表:模型

model_name
quantity

SQL:

SELECT DISTINCT model.model_quantity, model.model_name, tw.customer_name, tw.model FROM tw
RIGHT OUTER JOIN model
ON model.model_name=tw.model
AND tw.completed = 1 AND tw.stock = 0
ORDER BY model.id

我已将数组信息显示为显示目的,希望它能帮助理解合并的发生方式。

目前:

STC5
0
Andy Baker
Array ( [model_quantity] => 0 [model_name] => STC5 [customer_name] => Andy Baker [model] => STC5 ) 

STC5
0
Richard Cash
Array ( [model_quantity] => 0 [model_name] => STC5 [customer_name] => Richard Cash [model] => STC5 ) 

预期结果一列,列出匹配模型的所有名称:

STC5
0
Andy Baker
Richard Cash

0 个答案:

没有答案