sql - How can I create a new table based on merging 2 tables without joining certain values? -


i asked question earlier, wasn't able explain myself clearly.

i made graphic explain i'm trying do.

enter image description here

i have 2 separate tables inside same database. 1 table called 'consumers' 200 fields including 1 called 'meter_numbers*'. , 1 other table called 'customer_info' 30 fields including 1 called 'meter'. these 2 meter fields join or whatever method based on. problem not meter numbers in 2 tables match , null values , value of 0 in both tables.

i want join information records have matching meter numbers between 2 tables, keep null , 0 values own records. there null , 0 values in both tables don't want them join together.

there few duplicate field names, location shown in graphic. if it's easier fix these duplicate field names manually can that, it'd cool able programmatically.

the key need result in new table!

this process 1 time thing, not often.

hopefully, explained , if can me out that'd awesome!

if more information needed, please let me know.

thanks.

insert new_table select * (select a.*, b.* consumers     inner join customerinfo b on a.meter_number = b.meter , a.location = b.location     a.meter_number not null , a.meter_number <> 0 union      select a.*, null meter, null customerinfo_location, null field2, null field3      consumers      a.meter_number null or a.meter_number = 0 union      select null meter_number, null location, null field4, null field5, b.*      customerinfo b      b.meter null or b.meter = 0) c 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -