Table:2018
No Email
1 Lilly@gmail.com
2 brens@gmail.com
3 susan@gmail.com
4 resh@gmail.com
Table:2017
No Email
1 chitta@gmail.com
2 resh@gmail.com
3 brens@gmail.com
4 minu@gmail.com
Table:2016
No Email
1 brens@gmail.com
2 chitta@gmail.com
3 lisa@gmail.com
4 monay@gmail.com
5 many@gmail.com
Table:2019
No Email
1 brens@gmail.com
2 chitta@gmail.com
3 rinu@gmail.com
4 emma@gmail.com
I need to perform Union of tables 2018,2017,2016 without any duplicate emails minus table 2019 ,Result should look like
RESULT
No Email
1 Lilly@gmail.com
2 susan@gmail.com
3 resh@gmail.com
4 minu@gmail.com
5 lisa@gmail.com
6 monay@gmail.com
7 many@gmail.com
Minus operation is not available in Mysql.
select a.*from(select *from y2018 union select *from y2017 where not exists(select *from y2018 where y2018.email=y2017.email ) union select *from y2016 where not exists(select *from y2018 where y2018.email=y2016.email ))a LEFT OUTER JOIN y2019 b on a.email=b.email where b.email is null ;
This gives the result but does not eliminate the duplicates in (2017 union 2016)
some one please help me