If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Querying 2 tables for results

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-03, 10:35
lm28ness lm28ness is offline
Registered User
 
Join Date: Aug 2003
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 08-18-03, 10:59
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Querying 2 tables for results

Quote:
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.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On