1

我有两个表,如下所示: 表 1:

name    surname    age
----    -------    ---
 a         b       null
 c         d       null

表 2:

age
---
 1 
 4

我想将它们组合到第一个表(Table1)中

name    surname    age
----    -------    ---
 a         b        1
 c         d        4

(它们具有相同的行数)我该如何组合它们?

4

1 回答 1

7

也许你想要这个,

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
于 2012-12-29T08:13:09.303 回答