2013-10-17 74 views
0

我有一个关于在mysql中加入两个表的问题。在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 

我想加盟型动物行2个表。我尝试了左,内和右连接,但不可能。结果以相似的行检索我。我喜欢的结果一样显示在this链接:

这是一个很难回答的问题:P

+1

显示我们的表结构和你有什么尝试 –

+1

请摆脱图片结构,并使用[小提琴](http://sqlfiddle.com) –

+0

表时间轴:结构:http://i.imgur.com/THmV5hp.jpg资料:http:///i.imgur.com/YaabHtf.jpg – 50l3r

回答

0

你可以使用下面的查询所需的结果:

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 
+0

这个查询返回这个数据:http://i.imgur.com/sh4TBiF.jpg我需要这个数据结构:http:// i.imgur.com/QZM7bsS.jpg – 50l3r

+0

我编辑了查询,请检查一次。 – dipendra

+0

非常感谢您的解决方案,但你不明白我的问题。也许我认为这是一个虚假的查询。在这个数据结果中:http://i.imgur.com/QZM7bsS.jpg 1.4行对应timeline_personal表格第2,3行,时间表表格的时间行 – 50l3r

相关问题