The SQL Workshop: Learn to create, manipulate and secure data and manage relational databases with SQL by Frank Solomon & Prashanth Jayaram & Awni Al Saqqa

The SQL Workshop: Learn to create, manipulate and secure data and manage relational databases with SQL by Frank Solomon & Prashanth Jayaram & Awni Al Saqqa

Author:Frank Solomon & Prashanth Jayaram & Awni Al Saqqa [Solomon, Frank]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2019-12-30T00:00:00+00:00


Build a list of all the OrderID values in the Orders table, as follows:USE packt_online_shop;

SELECT O.OrderID

FROM Orders O;

Add a WHERE clause to the query. Use NOT IN to filter the Orders table with the subquery that we built first. Sort the result set by OrderID:USE packt_online_shop;

SELECT O.OrderID

FROM Orders O

WHERE O.OrderID NOT IN (SELECT OrderID FROM ORDERITEMS)

ORDER BY O.OrderID;

The output is as follows:

Figure 7.3: Printing the ID that's not common for the order in the OrderItems table

In this exercise, we filtered out the order ID for the order that does not have a corresponding entry in the OrderItems table.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.