mysql - How to create a union of two tables with null values? -


i have 2 mysql tables, "ucharacters" , "uplaces," both have column "ucharacter." there overlap between ucharacter columns in 2 tables, values unique each. each table has columns "episode" , "line," "uplaces" table has "place" column. create simple version of schema:

create table ucharacters (   ucharacter varchar(50),   episode int(2),   line int(6)   );  create table uplaces (   ucharacter varchar(50),   episode int(2),   line int(6),   place varchar(40)   );  insert ucharacters values ('molly', 4, 123); insert ucharacters values ('leo', 5, 567); insert uplaces values ('leo', 5, null, 'athens'); 

i want select temporary table combines these, preserves every line each table, null values appropriate. result like:

ucharacter  episode line place molly       4       123  null leo         5       567  null leo         7       null athens 

here code now:

select tabkey.ucharacter,   ucharacters.episode, ucharacters.line,   uplaces.episode, uplaces.line, uplaces.place    (select ucharacters.ucharacter ucharacters  union  select uplaces.ucharacter uplaces) tabkey  left join  ucharacters on tabkey.ucharacter = ucharacters.ucharacter  left join  uplaces on tabkey.ucharacter = uplaces.ucharacter; 

this works fine first line (molly, 4, 123, null) gives 2 identical lines of (leo, 5, 567, athens), combining 2 tables. how can result typed above instead?

http://sqlfiddle.com/#!2/a7013e/1

thanks!

i want select temporary table combines these, preserves every line > each table, null values appropriate. result like:

if want do, not use query below?

select ucharacter, episode, line, null ucharacters union select ucharacter, episode, line, place uplaces; 

http://sqlfiddle.com/#!2/a7013e/17/0


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -