w3resource

AdventureWorks Database: Any distinct businessentityid from the first query not found in the second query

SQL Query - AdventureWorks: Exercise-136 with Solution

136 From the following table write a query which is the combination of two queries. Return any distinct businessentityid from the 1st query that aren't also found in the 2nd query. Sort the result set in ascending order on businessentityid.

Sample table: Person.BusinessEntity


Click to view Full table

Sample table: Person.Person


Click to view Full table

Sample Solution:

SELECT businessentityid   
FROM person.businessentity    
except  
SELECT businessentityid   
FROM person.person
WHERE person.persontype = 'IN'  
ORDER BY businessentityid;

Sample Output:

businessentityid|
----------------+
               1|
               2|
               3|
               4|
               5|
               6|
               7|
               8|
               9|
              10|
              11|
...			

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: A distinct businessentityid must be returned by both queries.
Next: Combine ProductModelID and Name columns from two tables.


What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

Convert Timestamp to date in MySQL Query:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

Database: MySQL

Ref : https://bit.ly/3EJPnMQ