Custom Search
 


Create working tables to demonstrate how to mimic set operators MINUS, EXCEPT, INTERSECT in MySQL


Here are the queries I used to create 4 working tables to demonstrate how to achieve the same effect as using set operators MINUS, EXCEPT, INTERSECT in MySQL because MySQL does not support these set operators.

Table 1: suppliers_1

This query creates a table by using the original suppliers table in Northwind database. Note that only SupplierID 1 to 5 are loaded.

create table suppliers_1
as
select SupplierID, CompanyName, ContactName, ContactTitle
from suppliers
where SupplierID between 1 and 5;

Here is the table created.

Table 2: suppliers_2

This query creates another table. Note that only SupplierID 3 to 8 are loaded.

create table suppliers_2
as
select SupplierID, CompanyName, ContactName, ContactTitle
from suppliers
where SupplierID between 3 and 8;

Here is the table created.

Table 1 with checksum: suppliers_1_md5

This query creates a table from the original suppliers table. In addition, it also creates a new column called MD5 at the end. The MD5 column contains checksum values calculated by concatenating column SupplierID, CompanyName, ContactName, ContactTitle in suppliers table. Note that only SupplierID 1 to 5 are loaded.

create table suppliers_1_md5
as
select SupplierID, CompanyName, ContactName, ContactTitle,
md5(concat(SupplierID, CompanyName, ContactName, ContactTitle)) as Checksum
from suppliers
where SupplierID between 1 and 5;

Here is the table created.

Table 2 with checksum: suppliers_2_md5

This query creates another table with a new column for checksum values. Note that only SupplierID 3 to 8 are loaded.

create table suppliers_2_md5
as
select SupplierID, CompanyName, ContactName, ContactTitle,
md5(concat(SupplierID, CompanyName, ContactName, ContactTitle)) as Checksum
from suppliers
where SupplierID between 3 and 8;

Here is the table created.





Other tutorials in this category

1. Using Inner Joins to Combine Data from Two Tables

2. Using Outer Joins to Combine Data from Two Tables

3. Another Example for Outer Joins (three tables)

4. Using Self Joins to Combine Data from the Same Table

5. SQL Set Operators - a Visual Guide to UNION, UNION ALL, MIMUS/EXCEPT, INTERSECT

6. Using UNION to Append Result Sets

7. How to do MINUS/EXCEPT and INTERSECT in MySQL

8. How to Simulate Full Join in MySQL - Part 1: return both matched and unmatched rows

9. How to Simulate Full Join in MySQL - Part 2: return unmatched rows only

10. How to Simulate Full Join in MySQL - Part 3: use UNION to simulate FULL JOIN

11. Use Cross Join to Combine Data in MySQL

12. Differences Between Join and Union

Back to Tutorial Index Page


Copyright © 2024 GeeksEngine.com. All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

 
Home | Feedback | Terms of Use | Privacy Policy