w3resource

AdventureWorks Database: Return any distinct values that are returned by both the queries

SQL Query - AdventureWorks: Exercise-132 with Solution

132. From the following tables write a query in SQL to return any distinct values that are returned by both the query.

Sample table: production.Product


Click to view Full table

Sample table: production.WorkOrder


Click to view Full table

Sample Solution:

SELECT ProductID   
FROM Production.Product  
INTERSECT  
SELECT ProductID   
FROM Production.WorkOrder ;

Sample Output:

productid|
---------+
      753|
      765|
      970|
      781|
      951|
      839|
      732|
      887|
      350|
      959|
      758|
      819|
      826|
	  ...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Check for similarity of the values.
Next: Return any distinct values from first query, not found on the 2nd query.


What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.