0

Hi what sql query will I use to checks the "users_theme" table and finds all the user_id's which exist in this table and not the "users" table. Once I have those id's that exist in the user_theme table that does not exisit in the users table I want to delete all rows with that user id from the users_theme.

for example In simple terms if user_id: 2546 exist in "users_theme" table but does not exist in "users" table delete the row of 2546

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Jaulm
0

I believe you could do a something like this

select user_id from users_theme
where id not in (select id from users);

Then you would have a list of the ids that exist in the users_table that do not exist in users.
If you wanted to use that list for a delete, you could create a temp table and use that in your delete statement. something like:

create table temp_table as
select user_id from users_theme
                          where id not in (select id from users);
delete from users_theme
where user_id in temp_table;

Hope that helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.