我有两张表,如下所示: 表1:
name surname age
---- ------- ---
a b null
c d null
表2:
age
---
1
4
我想将它们组合到第一个表(Table1)中,如
name surname age
---- ------- ---
a b 1
c d 4
(它们具有相同的行数)如何组合它们?
答案 0 :(得分:6)
也许你想要这个,
SELECT a.Name, a.SurName, b.Age
FROM
(
SELECT @row := @row + 1 RankNo,
Name, Surname
FROM Table1, (SELECT @row := 0) r
) a
INNER JOIN
(
SELECT @row1 := @row1 + 1 RankNo,
Age
FROM Table2, (SELECT @row1 := 0) r
) b ON a.RankNo = b.RankNo