从SQL Server 2005和2008中的两个表中获取数据 [英] Fetch Data From Two table in sql server 2005 and 2008
问题描述
亲爱的朋友
我有两个表t1和t2.
表t1结构
支付码
名称
表t2的结构
支付码
名称
还有一件事,我的表中没有主键和外键的概念.
t1中的记录
1)111 sunil
2)222 sunit
t2中的记录
1)333 narayan
2)444 sumit
我想要查询中的所有记录.............
请尽快帮助我.
Dear Friends
I have two tables t1 and t2.
Table t1 Structure
Paycode
Name
Table t2 Structure
Paycode
Name
And one more thing there is no concept of primary key and foreign key in my table.
Records in t1
1) 111 sunil
2) 222 sunit
Records in t2
1) 333 narayan
2) 444 sumit
and I want all the records from query.............
Please help me out as soon as possible.
推荐答案
尝试一下
select * from t1 UNION ALL select * from t2
首选解决方案是:
The prefer solution is:
SELECT *
FROM t1
UNION ALL
SELECT *
FROM t2
了解更多:
文字查询-基础知识 [选择 [选择示例 [ UNION [订购 [
Read more:
Writing queries - basics[^]
SELECT[^]
SELECT Examples[^]
UNION[^]
ORDER BY[^]
根据您提供的有关表格的信息,我将建议重新设计表结构.
您是否真的需要将行分开到两个不同的表?您能代替一张桌子吗?如果行之间存在某种差异,例如第一个表中的行有效,而另一张表中的行无效,那么您是否可以使用额外的列来定义行的状态(仅作为示例).
Based on the information you have given about the tables, I''d suggest a redesign of the table structure.
Do you really need to separate the rows to two different tables? Could yo uuse one table instead? If the rows are somehow different, for example rows in the first table are valid while in the other table they are invalid, could you use an extra column to define the state of the row (just an example).
这篇关于从SQL Server 2005和2008中的两个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!