Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combination of tables

 
denice
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to combine 4 tables into a brand new table?? Any sugguestion on how to do it??

-thx-
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thenice,

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!
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH

Danephew
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic