我有一个关于在mysql中连接两个表的问题。
我有一个数据模型:
timeline:
structure: i.imgur.com/THmV5hp.jpg
data: i.imgur.com/YaabHtf.jpg
timeline_personal:
structure: i.imgur.com/H0VzTMw.jpg
data: i.imgur.com/rX3NhOb.jpg我喜欢用不同的行连接两个表。我尝试与左,内和右连接,但这是不可能的。结果在类似的行中检索到我。我喜欢这链接中显示的结果:
这是一个很难回答的问题:
发布于 2013-10-17 09:49:34
您可以使用以下查询获得所需的结果:
select
concat('T-',timeline.TimelineId), timeline.UsuarioId, timeline.TimelineFecha, "" Timeline, timeline.Evento, timeline.JuegoId, 0 TimelinePadre
from
timeline
union
select
concat('TP-',timeline_personal.TimelineId), timeline_personal.UsuarioId, timeline_personal.TimelineFecha, timeline_personal.Timeline, "0" Evento, "0" JuegoId, timeline_personal.TimelinePadre
from
timeline_personal
order by UsuarioIdhttps://stackoverflow.com/questions/19423094
复制相似问题