mardi 3 mars 2015

Query for orders that contain a product without using sub-query



Order
-----
OrderId

OrderDetail
-----------
OrderDetailId
OrderId
ProductId


How do I write a query that returns all orders that contain a specific product without using a sub-query?


I don't want to write a sub-query because I want to encapsulate the query in a view and use a WHERE clause on the view to supply the product id instead of having a stored procedure and supplying a parameter.


I figure the only way to do this is with a GROUP BY on order but even then I don't know how to have the aggregate column resolve to whether the product is amongst the order details.





Aucun commentaire:

Enregistrer un commentaire