考慮訂單。訂單將包含一個或多個訂單項。每個訂單項都適用於特定的產品。如何從兩個表中的結果中獲得一個ID
給定一個過濾表與幾個產品,我怎麼會得到至少有所有列在第二個表中的產品的訂單ID?
table Orders(
OrderId int
)
table LineItems (
OrderId int,
LineItemId int,
ProductId int
)
table Filter (
ProductId int
)
數據
Orders
OrderId
--------
1
2
3
LineItems
OrderId LineItemId ProductId
------- ---------- ---------
1 1 401
1 2 502
2 3 401
3 4 401
3 5 603
3 6 714
Filter
ProductId
---------
401
603
查詢
期望的結果: 的OrderId:3
是的我通常喜歡加入子選擇我自己。謝謝! – NotMe 2010-02-10 22:20:11
標記此爲最完整的答案。因爲他們得出了同樣的結論,所以我都贊同。謝謝大家。 – NotMe 2010-02-11 03:09:42