I am working on a question where I have two tables. They share the same columns, so I did a union all on them. I'm not sure if that's the best way. I am supposed to delete the rows that match in another table and I am not getting that right. I'm trying to delete the rows from the third table that have the same username as in the joined tables 1 & 2. Also how do I name the newly joined table? I use R a lot so am used to creating new tables but not sure here.
Table 1, 2, and 3 have 3 columns, all the same. They are Company, Username, and Time. Table 1, 2 are merged. If a username is in Table 3 and the Table 1,2, we want that dropped in Table 1,2.
Example of what the data looks like I want to merge table 1 and 2 and remove entries that have a username in table 3. Table 3 is not being added to these tables.
table1
Company Username Time
Company1 Bobbio123 23:77
Company1 Yellow8 12:12
Company1 Travis9 14:16
Company1 Leonardy 05:00
Company1 Yessir 06:00
table 2
Company2 Sally111 20:10
Company2 TammyTammy 02:11
Company2 ScammyDavis 06:17
table 3
Company3 Dannyeh 12:20
Company3 ScammyDavis 01:11
Company3 Leonardy 05:00
What I want
Company Username Time
Company1 Bobbio123 23:77
Company1 Yellow8 12:12
Company1 Travis9 14:16
Company1 Yessir 06:00
Company2 Sally111 20:10
Company2 TammyTammy 02:11
Here is what I've done:
SELECT * FROM table1
UNION ALL
SELECT * FROM table2
DELETE FROM table1
WHERE table1.username = table3.username OR table2.username = table3.username;
I've tried this as well and worked on one table only but it didn't work.
SELECT * FROM table1, table3
DELETE FROM table1
WHERE table1.username = table3.username