Sql Query for inserting data from 2 tables into one based on name -


hello 2 tables of data different sources, need combine of them 1 main table.

database layout:
table a
-name
-ranking
-score

table b
-name
-ranking
-score

table new
-name
-ranking a
-score a
-ranking b
-score b

i want take data table , b , insert table new based on name. not sure how in sql, appreciated

assuming every record in tablea has corresponding record in tableb:

insert tablenew     (name, rankinga, scorea, rankingb, scoreb)     select a.name, a.ranking, a.score, b.ranking, b.score         tablea             inner join tableb b                 on a.name = b.name 

if assumption invalid, then:

insert tablenew     (name, rankinga, scorea, rankingb, scoreb)     select a.name, a.ranking, a.score, b.ranking, b.score         tablea             left join tableb b                 on a.name = b.name     union     select b.name, a.ranking, a.score, b.ranking, b.score         tableb b             left join tablea                 on b.name = a.name         a.name null 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -