Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    40

    Unanswered: identifying common elements of two columns of two tables

    I am trying to get the list of ids that appears in two tables:
    select id1 from table1 where id1 IN (SELECT id2 from table2).
    However this query does not give the desired results.
    Why?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Can id2 be NULL? If yes, use the following

    Code:
    select id1 
    from table1 
    where id1 IN (SELECT id2 
                  from table2
                  WHERE id2 <> NULL)

  3. #3
    Join Date
    Sep 2010
    Posts
    40
    Is there any faster way to solve this? I mean to check if the elements of some columns are also in a column of some other table?
    Thanks

  4. #4
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    What exactly do you mean with "elements of some columns"?

    Please show us the table definitions (as CREATE TABLE statements), some sample data (as INSERT INTO statements) and the output you expect to see.

    And please use [code] tags to make your SQL readable.
    For details on how to use the tag, please see: http://www.dbforums.com/misc.php?do=bbcode

Posting Permissions

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