0
私はSQLが初めてで、現在のSQLクエリは次のとおりです:-

SELECT
    CONCAT(LastName,', ',FirstName)AS 'Name',</li>
    City,
    Country,
    ShipCity AS 'Shipped City'
From 
    itstudies.employees
INNER JOIN
    Orders
ON Employees.EmployeeID = Orders.EmployeeID
WHERE City = ShipCity;
このクエリは、出力を次のように示します。

(出力の一部のみが示されています。)

Name            City     Country     Shipped City
Smith, Jo       York       UK            York
Avery, Paul     Dallas     USA           Dallas
Avery, Paul     Dallas     USA           Dallas 
Kris, Jan       York       UK            York
Kris, Jan       York       UK            York
Hill, Ros       Boston     USA           Boston
重複を取り除き、クエリを次のように変更する必要があります:-

Name            City     Country     Shipped City
Smith, Jo       York       UK            York
Avery, Paul     Dallas     USA           Dallas
Kris, Jan       York       UK            York
Hill, Ros       Boston     USA           Boston
前もって感謝します。

4

2 に答える 2

2

You could just use

SELECT DISTINCT ...

but usually it is better to have a look at where the duplicates come from and work with a

GROUP BY

In this case you join with ORDERS and thus get duplicates for all orders of an employee. Is this join necessary? You could use

WHERE EXISTS (SELECT 1 FROM Orders WHERE Orders.EmployeeId=Employees.EmployeeId)

to get only employees who ordered.

于 2013-08-23T08:15:49.827 に答える
0

シンプル: DISTINCT キーワードを使用します。

詳細については、 http://www.w3schools.com/sql/sql_distinct.aspを参照してください ;)

于 2013-08-23T08:17:53.483 に答える