表“科目”包含列:
sub_date, sub_content, student_id
2014-10-03, english, 1
2014-10-09, maths, 2
2014-10-11, biology, 1
和 桌面游戏包含列:
game_date, game_content, student_id
2014-10-05, Hockey, 1
2014-10-18, Tennis, 1
2014-10-20, Cricket, 2
我希望按日期显示student_id 1个订单的所有详细信息(同时考虑sub_date和game_date
Date, Topic
2014-10-03, english
2014-10-05, Hockey
2014-10-11, biology
2014-10-18, Tennis
请帮忙
答案 0 :(得分:1)
select sub_date,sub_content from subjects where student_id = 1
UNION
select game_date,topic from games where student_id = 1
答案 1 :(得分:0)
你可以试试这个(即使听起来不是一个好主意):
SELECT tmp.sub_date AS Date,tmp.sub_content AS Topic
FROM (
SELECT sub_date,sub_content,student_id FROM subjects
UNION SELECT game_date,game_content,student_id FROM games
) tmp
WHERE tmp.student_id = 1 ORDER BY tmp.sub_date;