我有表A:
id username firstname event_date 1 Ben lori 2014-01-27 2 Ben lori 2014-01-04 3 Mary john 2014-01-28
我有表B:
id username event_date 1 Ben 2014-01-23 2 Nicole 2014-01-26
我希望结果是这样的:是否有任何解决方案可以让我根据event_date对其进行组合和排序,例如一张桌子,像这样:
2 Ben lori 2014-01-04 1 Ben 2014-01-23 2 Nicole 2014-01-26 1 Ben lori 2014-01-27 3 Mary john 2014-01-28
这样我就可以使用while循环或mysql_fetch_assoc之类的内容来显示内容
基本上,您需要union all:
union all
select id, username, firstname, event_date from ((select id, username, firstname, event_date from tablea ) union all (select id, username, NULL as firstname, event_date from tablea ) ) t order by event_date;