2017-04-02 52 views
0

我在我的数据库中有两个表格#1是付款记录,#2是一个客户的销售记录现在我想在一张显示销售明细和付款明细的单一表格中显示两个表格的值立刻像第三张图片两个表格合并在单个表格中

那么我该如何编写查询来带来结果集我想要的。

我创造了PHP这种观点,MySQL的HTML

#1的缴费记录

enter image description here

#2的销售记录

enter image description here

期望的输出

enter image description here

销售表

enter image description here

付款表

enter image description here

+2

尝试新鲜事物了吗?以格式化文本(**不是图像**)的形式发布示例数据和预期输出,并发布您尝试的查询以及哪些内容无效? – GurV

+0

我使用内部连接,但它像交叉连接一样倍增。加入客户ID – Sariful

+0

你是如何获得当前图像的?可以为这两个表添加数据库方案和/或您的“join”尝试吗? – chris85

回答

3

任何有效的内部连接形式应该工作:

select * 
from payment, sale 
where payment.customer_id = sale.customer_id 

select * 
from payment inner join sale using (customer_id) 

select * 
from payment inner join sale on payment.customer_id = sale.customer_id 
+0

我用第三个,但乘以一切感谢 – Sariful