Skip to Main Content
  • Questions
  • multiple columns in table relating to same table

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Dave.

Asked: January 13, 2005 - 3:00 pm UTC

Last updated: January 13, 2005 - 3:36 pm UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

Hi Tom;

This might be an obvious question but I can't figure out the answer.

I have 2 tables. The first, called Table_A, contains case results for a vet lab. The table contains 1 record with the following columns:

Column Name Column Value
Animal Horse
Clinic_ID 1
Owner_ID 2


The second, called Table_B, is a mixture of names of owners and clinics.

Column Name Column Value
Name_ID 1
Name Vet Services

Name_ID 2
Name Joe Blow

I need to write a select statement that will pull the name of the clinic AND the name of the owner from Table B given only the ID's in Table A. I tried the following:

select b.????, b.????
from Table_A a, Table_B b
where a.Clinic_ID = b.Name_ID and a.Owner_ID = b.Name_ID;

I did not create these tables (I would have put owners and clinics in separate tables) but they are what I have to use. As you can see, I did not even know what to put in the select statement. Is there a solution to my problem? Thank you for your time.

Dave Halfpenny


and Tom said...

select *
from table_a, table_b clinic, table_b owners
where table_a.clinic_id = clinic.name_id
and table_a.owner_id = owner.name_id;

just have to join to it twice.



Is this answer out of date? If it is, please let us know via a Comment