Results 1 to 3 of 3

Thread: SQL Help - urgent

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Unhappy SQL Help - urgent

    Hi,

    I need an urgent help in writing an sql command. I have a combo box in which I need to write a query to fill it with mailboxnames(one of the fields in let us say Table1). But the catch is that I have another table (let us say Table2) which also has mailboxnames as one of its fields. The query should include only those mailboxnames from Table1 which are not present in Table2.

    Something like

    INSERT Mailboxnames from Table1 WHERE Table1.MailboxNames <is not present in> Table2.MailboxNames

    Thanks, any help would be greatly appreciated.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: SQL Help - urgent

    You could left join and only insert those that return null in table 2.

    Or you could use 'exists' or 'not exists' (you will need to read up on them) but the general gist is that you can supply a select statement in the exists part to look for those which exist (or don't) in the other table.

    Isn't the syntax:
    Code:
    INSERT INTO <table> (<fields>)
    SELECT <tables and fields>
    FROM <tables / joins>

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: SQL Help - urgent

    Right, thanks ecniv. I got the Left Join solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width