数据正在多次显示

时间:2014-09-16 09:25:20

标签: mysql

我在cust_vend_relation

下只有一条记录

但它被展示了两次。

QUERY

select cvr.customer_id,
cvr.address_label, 
cvr.vendor_name, 
cvr.vendor_id, 
vhd.locality, 
vhd.area, 
vhd.address,
vhd.city, 
vhd.state 
from cust_vend_relation cvr, vendor_home_delivery vhd
where cvr.vendor_id = vhd.vendor_id 
and cvr.address_label = 'Office' 
and cvr.customer_id = 3;

This is my sqlfiddle

我只需要显示表cust_vend_relation下的记录,这些记录与vendor_home_delivery下的记录相匹配。

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

按customer_id添加分组

select 
cvr.customer_id,
cvr.address_label, 
cvr.vendor_name, 
cvr.vendor_id, 
vhd.locality, 
vhd.area, 
vhd.address,
vhd.city,
vhd.state 
from cust_vend_relation cvr, vendor_home_delivery vhd
where cvr.vendor_id = vhd.vendor_id and cvr.address_label = 'Office' and cvr.customer_id = 3 group by customer_id;