【发布时间】:2015-09-23 18:19:41
【问题描述】:
SELECT distinct
sr.ServiceDescription,
os.ServiceID
FROM
OrderedServices as os
INNER JOIN
Orders as o ON o.OrderID = os.OrderID
INNER JOIN
ServiceRelation as sr ON os.ServiceID = sr.ServiceID
WHERE
o.OrderID = 2802882;
假设这会返回如下内容:
Service Description | ServiceID
--------------------------------
Basic Cable | 2
Extended Cable | 5
ExtendedPlus Cable | 5
Everything Cable | 10
但是,如果两个 ServiceIDs 匹配,我只想为 Service Description 返回一个值。看到ServiceID of 5 有两个Service Descriptions?我只想抓住其中一个。如何修改上面的 select 语句来完成这样的事情?
【问题讨论】:
标签: sql-server select inner-join