合并两个表数据 [英] combine two tables data

查看:62
本文介绍了合并两个表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示两个表中的数据,其中显示第一个表中的所有数据,显示第二个表中的一个数据,以便我使用哪个查询...并且没有公共字段
请解决方案

最简单的方法是:使用哈希表

1>创建具有必需字段的哈希表
2>将第一个表中的数据插入到此哈希表中.
3>然后使用while循环,使用第二个表中的列更新此哈希表.
4>最终从哈希表中进行选择.


除非数据表之间存在某些共性,否则这将行不通并且毫无意义,您最好将两个表一个接一个地显示.

如果有共同点,您可以使用:

 选择 c1  as  '   x',c2  as  '  y' 来自 table1
联盟
选择 d1 作为 '  x',d2  as  ' 来自 table2 


其中c1,c2是来自table1的列名称,而d1和d2是来自table2的列名称,"x"和"y"是查询中列的名称.


i want to display data from two tables in which display all data from first table and one one filed from second table so which query i will use... and there is no common field
Plz Reply

解决方案

Simplest way is: use hash table

1> Create hash table with requred field
2> Insert data from first table to this hash table.
3> Then using while loop, update this hash table with column from second table.
4> Finaly select from hash table.


Unless there is some commonality between the data tables then this will not work and does not make sense, you are better off showing two tables one after another.

If there is commonalty you can use :

select c1 as 'x',c2 as 'y' from table1
union 
select d1 as 'x', d2 as 'y' from table2


where c1, c2 are the column names from table1 and d1 and d2 from table2, ''x'' and ''y'' is the name for the columns in your query.


这篇关于合并两个表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆