join - How to combine a field from multiple tables into a single field in a MySQL View? -
i have multiple tables, each code
field. i'd combine values in separate code
fields new view in single code
field. want distinct code values in view. there codes in each table don't exist in of other tables, , there codes in each table exist in other tables.
what i'm trying fake sql doesn't work:
create view codes select table_a.code code, table_b.code code, table_n.code code table_a, table_b, table_n;
you need union
:
create view codes select code table_a union select code table_b union select code table_n
please note default, union
union distinct
: removes duplicates. if want keep them, use union all
.
Comments
Post a Comment