user2723240
user2723240

Reputation: 823

Merging Several Data Sets in MYSQL

I have a database in mysql with several different tables I would like to create one table.

Three of the the tables (A,B,C) have the same primary key and the last has a different primary key. So it might look like

Table A

ID | Phone| Address


Table B

ID| WorkPhone | Phone | Address


Table C

ID| Phone| Work_Address| WorkPhone

The biggest problem is that some of the information might be different despite the same ID. (So ID "Person1" might have two different phone numbers in the column "Phone" in the three tables.

For the first three tables, I'm trying to map them together but having problem with my syntax in MYSQL.

Here is what I have so far.

create table Total_Finance(

select combined_csv.*, finance.*, total_contribution.*

join

where combined_csv.id == finance.id

inner join 
where total_contribution.nationbuilder_id == combined_csv.nationbuilder_id

inner join 
where total_contribution.nationbuilder_id == finance.nationbuilder_id


);

Upvotes: 0

Views: 48

Answers (1)

Aleksandar Miladinovic
Aleksandar Miladinovic

Reputation: 1027

Hi here is how you should do JOIN sintax

SELECT tableA.*, tableB.*, tableC.*
FROM tableA
INNER JOIN tableB
ON tableA.ID = tableB.ID
INNER JOIN tableC
ON tableA.ID = tableC.ID

and here is SQL Fiddle for that to see how it's work http://sqlfiddle.com/#!9/d36f8/1

of course you can choose which column you want to select to do that instead of

 SELECT tableA.*, tableB.*, tableC.*

write

SELECT tableA.ID, tableA.Phone, ... tableB.Address... tableC.WorkPhone etc

Also about JOIN sintax you should know that there is a LEFT JOIN, RIGHT JOIN etc... you can see basics of that here http://www.w3schools.com/sql/sql_join.asp

Hope this help a little... if you have any question fill free to ask

GL!

Upvotes: 1

Related Questions