File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Combination of tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Combination of tables" Watch "Combination of tables" New topic

Combination of tables


Joined: Jul 18, 2004
Posts: 3
Does anyone know how to combine 4 tables into a brand new table?? Any sugguestion on how to do it??

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Well, you need to have some relationship between the columns in different tables to know which row in one table combines with a row in another table, and then you basically do a join.

something like

SELECT a.col1, a.col2, b.col1, b.col2 FROM a, b WHERE a.col1=b.col2

Once you get a ResultSet from this query, iternate through it and do inserts in the new table. Best to use a PreparedStatement with SQL something like

INSERT INTO new_table(a_col1, a_col2, b_col1) VALUES (?,?,?)

and setting the parameters as you iterate through each row.



The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Or you can use sql UNION but i guess you need to follow some guidelines
like same column names, same aritmetic expressions, aggregate functions and so on...thus you don't need to create and insert it into a new table. All the tables are combined as one resultset.
I agree. Here's the link:
subject: Combination of tables
It's not a secret anymore!