tags:

views:

102

answers:

2

I've got tables like this:

Table Articles
---------------
AID(PK)   Name   PublisherID   Words


Table Books
---------------
BID(PK)   Title  PublisherID   Date

I want to merge them like:

Table Total
---------------
Title   PublisherID

In this new table, Name in Table.Articles will belong to Title column, because.. Articles.Name and Books.Title mean the same thing :)

Any answers will be very appreciated :)

Thanks

+4  A: 
select title, publisherid from books
union all
select name, publisherid from articles
David Aldridge
In oracle, "CREATE TABLE as (the David Aldridge query)" to create the table with the apropiate structure and copy all the data.
Jonathan
thanks very much!!!it works perfectly :)i didn't know about 'all' command.
wooohoh
@wooohoh it is actually "union all". It is worth nothing that "union all" will list all the entries from your tables including duplicates. Using just "union" will eliminate duplicates - each entry will be listed only once. You need to decide which behaviour is desirable in your scenario
kristof
+1  A: 

As I understand, you are looking for the result of this:

select name, publisherId
from TableArticles
union 
select title, publisherId
from TableBooks
FerranB
Problem about this query is, if there are same name/title, they will be merged. But thanks for a reply anyway!!!
wooohoh