0

我有 2 张桌子,每张桌子都有 3 列。我想得到一列,以便每个表中的一列一个接一个地附加

 eg:- suppose one column in a table contains  hai, how, are, you.
 and another column in another column contains i, am, fine.
 i want a query which gives hai, how, are, you,i,am,fine. in just one column

任何人都可以在sql中对此进行查询...

4

2 回答 2

2

如果我正确理解了您的架构,您就有了这个

Table1:  Column1
          hai,
          how,
          are,
          you.

Table2: Column2
          i,
          am,
          fine.

做这个:

Insert Into Table1 (Column1)
Select Column2 From Table2

你会得到这个:

Table1: Column1
         hai,
        how,
        are,
        you.
         i,
        am,
        fine.

如果您有 3 列然后执行以下操作:

Insert Into Table1 (Column1, Column2, Column3)     //the (Column1, Column2, Column3) is not neccessary if those are the only columns in your Table1
Select Column1, Column2, Column3 From Table2       //the Select Column1, Column2, Column3 could become Select * if those are the only columns of your Table2

编辑:如果您不想修改任何表,请执行此操作。

Select Column1, Column2, Column3
From Table1
UNION ALL
Select Column1, Column2, Column3
From Table2
于 2012-11-06T09:50:31.730 回答
2

你的问题不是很清楚。对它的一种解释是您希望将两者合并:

select column
from table1
union
select column
from table2;

如果您真的想要两个表中的所有行(而不是不同的值),UNION ALL 将比 UNION 更快。

如果您希望行按特定顺序排列,请务必指定 ORDER BY 子句。

于 2012-11-06T09:54:08.277 回答