Database clean up

  • Hi,

    I have a users table, which has a list of all users in my application.  There are three tables where the user id (primary key of users table) is referred.  Now, I want to clean up my users table.  I want to delete all users that are not referred in any of these three tables.  In one table, the user is referred twice.

    Could anyone please help me out?  Thanks in advance.

    Sangeeth

  • Suppose you have the tables and fields:

    UserTable - UserID (your primary key)

    Table1 - RefUserID1 (this is  a reference field (foreign key) to userIDin the Usertable)

    Table2 - RefUserID2, Table 3 -RefUserID3

    You would want something like this:

    SELECT * (or delete )

    FROM UserTable

    WHERE UserID NOT IN

    (select distinct RefUserID1 from Table1 UNION select distinct RefUserID2 from table2 UNION select distinct RefUserID3 from Table3)

    Regards,Yelena Varsha

  • Yelena,

    Thanks for the help!

    Regards

    Sangeeth

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply