1
我想要做的故事自联接,使一对客户,但我不希望同样对出现两次,我用这个代码如何让相同的字段在SQL自连接中不出现两次?
SELECT DISTINCT A.customer_num AS ' num1'
, B.customer_num AS 'num2'
, A.customer_name AS 'name1'
, B.customer_name AS 'name2'
, A.city AS 'city'
FROM tbl_customer A
, tbl_customer B
WHERE A.customer_num <> B.customer_num
AND A.city = B.city ;
它给我的记录,但对得到重复,这就是我得到的结果My Result,如1和第6对是相同的,我得到了 ,我正在使用MySQL Workbench。
我还需要DISTINCT吗?或不@dasblinkenlight –
@HarryKashyap不,你应该可以删除'DISTINCT'子句。 – dasblinkenlight