Skip to Content
MySQL 8 Cookbook
book

MySQL 8 Cookbook

by Karthik Appigatla
January 2018
Intermediate to advanced
446 pages
12h 57m
English
Packt Publishing
Content preview from MySQL 8 Cookbook

Finding mismatched rows between tables

Suppose you want to find rows in a table that are not in other tables. You can achieve this in two ways. Using the NOT IN clause or using OUTER JOIN.

To find the matched rows, you can use normal JOIN, if you want to find mismatched rows, you can use OUTER JOIN. Normal JOIN means A intersection B. OUTER JOIN gives matching records of both A and B and also gives unmatched records of A with NULL. If you want the output of A-B, you can use the WHERE <JOIN COLUMN IN B> IS NULL clause.

To understand the usage of OUTER JOIN, create two employee tables and insert some values:

mysql> CREATE TABLE employees_list1 AS SELECT * FROM employees WHERE first_name LIKE 'aa%';Query OK, 444 rows affected (0.22 sec)Records: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Cookbook

MySQL Cookbook

Paul DuBois
Advanced MySQL 8

Advanced MySQL 8

Eric Vanier, Birju Shah, Tejaswi Malepati

Publisher Resources

ISBN: 9781788395809Other