从具有相同列的两个表中选择数据 [英] Select Data from two tables with identical columns

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

问题描述

我有两个具有相同结构的表;一个包含永久性数据,另一个被定期清除并重置.

I have two tables that have the same structure; one contains permanaent data, and one is cleared and reset on a regular basis.

我需要对两个表都使用相同的select语句,就像它们只是一张表一样

I need to make the same select statement work on both as if they were just one table

这是我尝试过的:

SELECT * FROM ab在1处;

SELECT * FROM a,b WHERE 1;

ab具有相同的结构;

Where a and b have the same structure;

推荐答案

您可能正在查询中使用UNION:

You may be looking at using a UNION in you query:

Select * from a
UNION
Select * from b

注意:最好对列名进行限定,而不要使用*引用.如果您的两个表进行了架构更改,但您仍想撤回两个表共有的所有数据,这也将使查询仍然有用.

Note: It is better practice to qualify your column names instead of using the * reference. This would also make the query still useful if your two tables underwent schema changes but you still wanted to pull back all the data the two tables had in common.

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

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