Mysql 如何加入/联合查询

Mysql 如何加入/联合查询,mysql,Mysql,我有一个快速的问题,我找不到答案 (SELECT Student_Name AS 'First two from Quiz' FROM events WHERE Event_Name LIKE 'Quiz' ORDER BY Student_Name LIMIT 2) UNION ALL (SELECT Student_Name as 'Last two from Quiz' FROM (SELECT Student_Name FROM events WHERE Event_Name LIKE

我有一个快速的问题,我找不到答案

(SELECT Student_Name AS 'First two from Quiz' FROM events WHERE Event_Name LIKE 'Quiz' ORDER BY Student_Name LIMIT 2)
UNION ALL
(SELECT Student_Name as 'Last two from Quiz' FROM (SELECT Student_Name FROM events WHERE Event_Name LIKE 'Quiz' ORDER BY Student_Name DESC LIMIT 2) as q ORDER BY Student_Name)
UNION ALL
(SELECT Student_Name as 'Last two from Sqlizer' FROM (SELECT Student_Name FROM events WHERE Event_Name LIKE 'Sqlizer' ORDER BY Student_Name DESC LIMIT 2) as w ORDER BY Student_Name)
UNION ALL
(SELECT Student_Name AS 'First two from Sqlizer' FROM events WHERE Event_Name LIKE 'Sqlizer' ORDER BY Student_Name LIMIT 2)

这是我的一个小代码。我需要一个一个地展示它们。就像一个挨着另一个。由于union all,它在一列中显示所有。你有解决那个问题的办法吗?拜托,这是时间问题。我想在两个小时内完成。

我确信有一个更优雅的解决方案,但这是我有时间想出的。您可以使用连接将表并排放置,但这将为您提供所有可能的数据排列,这是我们不需要的。因此,我向四个表中的每个表添加了一个计数器,并且只输出一个数据排列(计数器都相等的排列):


你能重新措辞你的问题吗?可能,预期产出和实际产出可能会有助于实现这一目标,但没有必要这样做。问题已经解决了,非常感谢您的解决方案!感谢您的快速回复!再次感谢你。祝你愉快day@J.Borrow我很高兴能帮助你。如果你喜欢这个答案,如果你能投赞成票并接受它作为解决方案,那会有帮助。
SELECT a.Student_Name AS 'First two from Quiz', b.Student_Name as 'Last two from Quiz', c.Student_Name as 'Last two from Sqlizer', d.Student_Name AS 'First two from Sqlizer'
FROM
(SELECT  @s:=@s+1 serial_no, Student_Name FROM events, (select @s:=0) as s WHERE Event_Name LIKE 'Quiz' ORDER BY Student_Name LIMIT 2) as a,
(SELECT  @s1:=@s1+1 serial_no, t2.Student_Name FROM (SELECT Student_Name FROM events WHERE Event_Name LIKE 'Quiz' ORDER BY Student_Name DESC LIMIT 2) as t2, (select @s1:=0) as s) as b,
(SELECT  @s2:=@s2+1 serial_no, t3.Student_Name FROM (SELECT Student_Name FROM events WHERE Event_Name LIKE 'Sqlizer' ORDER BY Student_Name DESC LIMIT 2) as t3, (select @s2:=0) as s) as c,
(SELECT  @s3:=@s3+1 serial_no, Student_Name FROM events, (select @s3:=0) as s WHERE Event_Name LIKE 'Sqlizer' ORDER BY Student_Name LIMIT 2) as d

WHERE a.serial_no = b.serial_no and c.serial_no = d.serial_no and b.serial_no = c.serial_no