w3resource

AdventureWorks Database: A distinct businessentityid must be returned by both queries

SQL Query - AdventureWorks: Exercise-135 with Solution

135 From the following tables write a query in SQL to fetch distinct businessentityid that are returned by both the specified query. Sort the result set by 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    
INTERSECT   
SELECT businessentityid   
FROM person.person
WHERE person.persontype = 'IN'  
ORDER BY businessentityid;

Sample Output:

businessentityid|
----------------+
            1699|
            1700|
            1701|
            1702|
            1703|
            1704|
            1705|
            1706|
            1707|
            1708|
            1709|
            1710|
            1711|
...	

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Fetch any distinct values from left query of EXCEPT that aren't present in the query to the right.
Next: Any distinct businessentityid from the first query not found in the second query.


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