Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merging two tables with same column in meaning into one

Tags:

sql

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

like image 562
Vincent Avatar asked Jul 13 '09 13:07

Vincent


2 Answers

select title, publisherid from books
union all
select name, publisherid from articles
like image 145
David Aldridge Avatar answered Nov 14 '22 23:11

David Aldridge


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

select name, publisherId
from TableArticles
union 
select title, publisherId
from TableBooks
like image 28
FerranB Avatar answered Nov 14 '22 22:11

FerranB