Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Tables

Status
Not open for further replies.

f5snopro

Technical User
Feb 6, 2003
23
US
I have 17 tables all with server related data (Make, Model, utilization, etc.) There are duplicate fields across all the tables (i.e. Table1 has Make, Table2 has make). I want to create a query that builds a new table by combining the info of all 17. The catch is, I want to be able to rank the tables to say Table3 has reliability Level1, Table1 is 2, etc. So that I have the most reliable data set. (i.e. If Table3 has a Make and Table1 has a Make, Table3's make will be output.) How can I do this? Thanks.
 
You can union the tables together and add a separate column as you go so that you can order them. Try something like this:

select make, model, utilisation, 'Table1' as source
from table1
union
select make, model, utilisation, 'Table2' as source
from table2
union
select make, model, utilisation, 'Table3' as source
from table3
union
select make, model, utilisation, 'Table4' as source
from table4
order by 4;

That's how I'd do it anyway!
 
I see what you're saying, but what I'd like to do is take say Table A and combine it with Table B. Table A might not have a Make listed whereas Table B does. Table A's data is otherwise complete and reliable. I just need to append Table B's model listing. Is this possible?
 
Apologies if I'm trying to over-simplify this problem but could it not be solved with a normal join?

select tablea.name, tableb.make
from tablea, tableb
where tablea.id = tableb.id;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top