By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

Question on Select

P: n/a
Hi,
I have two tables,
Table A: item_id
Table B: item_id, ref_code
and i want to list all ref_codes in table B that are not referenced by
Table A.
Table A has about 3million records./ table B 200

What is the best way to do that ?

Thanks
Alex

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


select ref_code from tab_b where not exists (select * from tab_a where
item_id = tab_b.item_id);

make sure u have index on item_id in tab_a .

the above sql is quite efficient , other method is to use left join.
Alex wrote:
Hi,
I have two tables,
Table A: item_id
Table B: item_id, ref_code
and i want to list all ref_codes in table B that are not referenced
by Table A.
Table A has about 3million records./ table B 200

What is the best way to do that ?

Thanks
Alex

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.