1

我正在尝试列出下订单的客户姓名,他们来自某个县并从某个销售代表下订单。问题是,决赛桌会多次打印出他们的名字。我如何让他们每个人只打印一次名字?

SELECT cName
FROM customer INNER JOIN orders ON customer.cNo = orders.cNO,author
WHERE county = "Galway" AND saleRepName = "Jane Smith"; 
4

1 回答 1

2

您可以使用Distinct,但如果有很多记录,您可能会受到性能影响

SELECT DISTINCT
    cName 
FROM customer 
    INNER JOIN orders ON customer.cNo = orders.cNO,author 
WHERE county = "Galway" AND saleRepName = "Jane Smith";

Group By可能会更快,并允许您获得计数的额外好处:

SELECT
    count(1),
    cName 
FROM customer 
    INNER JOIN orders ON customer.cNo = orders.cNO,author 
WHERE county = "Galway" AND saleRepName = "Jane Smith";
GROUP BY cName

这将打印出如下内容:

3 John Doe
6 Jane Smith
1 Jersey Mike
于 2013-10-24T14:50:00.920 回答