我有一个关于连接 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
我喜欢连接不同行中的两个表。我尝试使用左连接、内连接和右连接,但这是不可能的。结果在相似的行中检索了我。我喜欢 this 中所示的结果链接:
这是一个很难的问题:P
最佳答案
您可以使用以下查询获得所需的结果:
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 UsuarioId
关于mysql - 连接mysql中具有相似列的两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19423094/