这是我的第一个查询
select r.[ProductID], [Name],
[Color], [UnitPrice] from [Production].[Product]r
inner join [Sales].[SalesOrderDetail]d
on d.productid = r.productid
**这是我的第二查询**
select [ProductID], [Name], [color] from
[Production].[Product] o where [ProductID] in
(select [UnitPrice] from [Sales].[SalesOrderDetail] s
where s.ProductID=o.ProductID)
firts查询正确地向我返回了我想要达到的目标,但是第一个小格返回了我null。我想使用第二查询具有相同的结果。有可能吗?
您可以使用exists
:
select p.*
from product p
where exists (select 1 from SalesOrderDetail sd where sd.productid = p.product);
您的第二个查询与第一个查询不同。它将ProductID
与UnitPrice
进行比较,这是无效的。应该不会产生任何结果。