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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.