我想将2个查询的结果附加到一个结果集中。
SELECT n.member_no, n.surname, n.first_name
FROM `names` AS n
WHERE member_no = '1003';
SELECT s.registration
FROM `system` AS s
WHERE s.RECNUM = 1;
这必须返回一条记录,其中包含名称表中的数据以及系统(一条记录)表中的数据
Member_no | surname | first_name | registration
--------------------------------------------------
1003 | Brown | Peter | My registration
答案 0 :(得分:2)
您可以使用CrossJoin
:
SELECT n.member_no, n.surname, n.first_name, s.registration
FROM names AS n
CROSS JOIN system s
WHERE n.member_no = '1003' and s.RECNUM = 1;
答案 1 :(得分:0)
我们可以基于registration
关联您的name
和row_number()
表。您可能要尝试以下查询。
SELECT rn.member_no, rn.surname, n.first_name, s.registration
FROM
(SELECT member_no, surname, first_name, row_number() over (order by member_no) rn
FROM `names`) n
LEFT JOIN
(SELECT row_number() over (order by RECNUM) rn, registration
FROM `system`) s on s.rn = n.rn
WHERE n.member_no = '1003'
答案 2 :(得分:0)
尝试这个。
SELECT DISTINCT n.member_no, n.surname, n.first_name,s.registration
FROM `names` AS n, `system` AS s
WHERE s.RECNUM = 1 AND member_no = '1003';