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
Sample table: Person.Person
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.
SQL: Tips of the Day
How to select rows with no matching entry in another table?
SELECT t1.ID FROM Table1 t1 LEFT JOIN Table2 t2 ON t1.ID = t2.ID WHERE t2.ID IS NULL
Ref: https://bit.ly/2QPhaD3
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook