Mysql join没有显示结果

时间:2017-05-21 22:07:53

标签: sql dreamweaver

尝试获取两个表来显示表中的数据。

表1(供应商)包含所有供应商详细信息 表2(repdetails)详细介绍了我们所有的销售代表和代理商

表1和表2都有RepID列

这是SQL查询:

SELECT suppliers.ID, suppliers.Suppliername, suppliers.postcode, suppliers.address, suppliers.phone, suppliers.fax, suppliers.email, suppliers.website, suppliers.Active, suppliers.imagename, suppliers.RepID, repdetails.RepID, repdetails.RepName, repdetails.RepEmail, repdetails.RepPhone 
FROM suppliers 
JOIN repdetails 
ON suppliers.RepID = repdetails.RepID

The blank fields show where the data should be

任何帮助都非常感谢!

1 个答案:

答案 0 :(得分:0)

您是从Supliers中选择的,您是否尝试过LEFT加入?我不确定你的数据库是怎样的,如果这对你的目标有用

SELECT 
    suppliers.`ID`, 
    suppliers.`Suppliername`, 
    suppliers.`postcode`, 
    suppliers.`address`, 
    suppliers.`phone`, 
    suppliers.`fax`, 
    suppliers.`email`, 
    suppliers.`website`, 
    suppliers.`Active`, 
    suppliers.`imagename`, 
    suppliers.`RepID`, 
    repdetails.`RepID`, 
    repdetails.`RepName`, 
    repdetails.`RepEmail`, 
    repdetails.`RepPhone` 
FROM suppliers 
LEFT JOIN repdetails ON suppliers.`RepID` = repdetails.`RepID`

您还要选择RepID两次。如果您在结果中需要此信息,可以尝试

    suppliers.`RepID` as s_repid,
    repdetails.`RepID` as r_repid, 

但也许你只想删除这些行或保留1?