从两个差异表中获取数据 [英] Fetching data from two diff tables

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

问题描述

我试图从两个不同的表中获取数据而不使用外键,并在单个网格视图中显示这两个表数据。如果是,请给我一个解决方案。

解决方案

检查 DEMO [ ^ ]您可以使用行号加入。


为此,您必须:



1)确保两个表的数据类型匹配,或者 CAST( )他们恰当。

2)您可以使用 UNION ALL 并将列重命名为与两个表匹配的内容



 选择 col1  as  [ColA],col2  as  [ColB]  from  table1 
union 全部
选择 col3 as [ColA],col16 as [ColB] 来自 table2


从table_name1中选择col1,col2,col3连接如内连接,左连接,右连接

从table_name2中选择col1,col2,col3

I am trying to fetching data from two different tables with different columns without foreign key and show these two table data in single grid view .any body have an idea about this if yes please give me solution for this....

解决方案

check DEMO[^] you can join using row number.


For this to work you must:

1) Ensure the data types of the two tables match or you CAST() them appropriately.
2) You can use UNION ALL and rename the columns to something that matches the two tables

select col1 as [ColA], col2 as [ColB] from table1
union all
select col3 as [ColA], col16 as [ColB] from table2


select col1,col2,col3 from table_name1 joins like inner join,left join,right join
select col1,col2,col3 from table_name2


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

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