Give a practical example of when you would use union interse
Give a practical example of when you would use union, intersect, or minus.
Or how or what would you use as the equivalent of intersect and minus in MySQL?
Solution
UNION is used to return distinct rows. When you have more than more table and you want to return ROWS from both the tables in distinct form.
It works like OR condition i.e when when the condition is satisfied it returns that row., When two tables returns the same row then only one of them will be present in the output.
INTERSECTION is used to return common rows.It works like AND condition i.e when when the condition is satisfied in both the rows it returns that row.
MINUS returns all the rows from first table except those that are returned by the second table.
MYSQL
INTERSECT can be implemented using inner Join in MySql
MINUS can be implemented in many ways using NOTEXISTS, OUTER JOIN , NOT IN etc
MINUS example
SELECT P.* FROM P WHERE P.name NOT IN (
SELECT Q.name
FROM Q
Thanks, I hope it clarifies. Let me know if there is anything
