mysql - How to join and get data with multiple table but the same structure? -
join multiple table , data in 1 line.
tbl_2012-08 (structure)
id | data_log | data_name
1 | 0001 | first 2 | 0002 | second
tbl_2012-09 (structure)
id | data_log | data_name
1 | 0003 | third
output:
data_log 0001 0002 0003
how join 2 table can extract data @ once.
case help
like:
create table or something
i don't know why have separate tables each month should able use union
query return data both tables:
select id, data_log, data_name `tbl_2012-08` union select id, data_log, data_name `tbl_2012-09`
i used union all
return rows both tables include duplicates (if any). cannot join
tables unless have common value in both tables , if have separate tables each month guess don't have common value in both tables.
as side note, might include include column can identify table data coming from:
select id, data_log, data_name, '2012-08' mth `tbl_2012-08` union select id, data_log, data_name, '2012-09' mth `tbl_2012-09`
my suggestion @ changing data structure, having separate table each month cumbersome manage.
if want return data_log
, use:
select data_log `tbl_2012-08` union select data_log `tbl_2012-09`
Comments
Post a Comment