Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    1

    Unanswered: Querying 2 tables for results

    Hello

    I want to return all of the values in one table that is not in another table.

    Ex. Table 1 has 2 columns - file_id, user_id
    Table 2 has the column file_id as well

    I want a query that returns all of the file_ids in table 2 that are not in table 1. What I noticed with my query is that it goes through the rows of table 1 and finds all file_ids in table 2 that are not in table for that row, even though the next row in table 1 has that id, in other words I will always get back all of the file_ids in table 2.

    What is the proper query for this?

    Thanks

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Querying 2 tables for results

    Originally posted by lm28ness
    Hello

    I want to return all of the values in one table that is not in another table.

    Ex. Table 1 has 2 columns - file_id, user_id
    Table 2 has the column file_id as well

    I want a query that returns all of the file_ids in table 2 that are not in table 1. What I noticed with my query is that it goes through the rows of table 1 and finds all file_ids in table 2 that are not in table for that row, even though the next row in table 1 has that id, in other words I will always get back all of the file_ids in table 2.

    What is the proper query for this?

    Thanks
    Oracle query:

    select file_id from table2
    MINUS
    select file_id from table1;

    I think "MINUS" is called "EXCEPT" in some DBMSs.

Posting Permissions

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