Understanding what an intersect is and learning how to use it in a SQL query 

An intersect allows you to combine two or more results sets that contain the distinct values of each set. The following screenshot shows you what results from an intersect:

MySQL doesn't support the INTERSECT SQL operator, but there is a workaround with a join. This can be done with DISTINCT and INNER JOIN. The following query shows you how to do this: 

SELECT DISTINCT a.playerid
FROM lahmansbaseballdb.batting b
INNER JOIN lahmansbaseballdb.appearances a
ON a.playerid = b.playerid
ORDER BY a.playerid;

The previous query gives you the results shown in the following screenshot:

The preceding results are the intersection of batting and appearances under playerid. The list of results contains only values that are in both tables. The DISTINCT operator removes duplicates, and the INNER JOIN returns the rows from both tables. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.69.244