简体   繁体   English

如何在具有相同列名的两个不同表上搜索相同数据

[英]How to search same data on two different tables with same column names

I have two tables with different names but similar schema and different data on them.我有两个名称不同但架构相似且数据不同的表。 I would like to search for certain data on both tables and combine the results.我想在两个表上搜索某些数据并合并结果。

for example:例如:

Table A: time, brand, model, color, engine_type表 A:时间、品牌、model、颜色、engine_type

Table B: time, brand, model, color, engine_model表B:时间、品牌、model、颜色、engine_model

engine_type and engine_model has the same data in reality, but column name's are different engine_typeengine_model实际数据相同,但列名不同

I would like to search certain engine_type or engine_model on both tables and show results.我想在两个表上搜索某些engine_typeengine_model并显示结果。 How can I do it?我该怎么做?

Use a union query:使用联合查询:

SELECT * FROM TableA WHERE engine_type = 'some value'
UNION ALL
SELECT * FROM TableB WHERE engine_model = 'some value';

You can use union if you dont want duplicate data as follows:如果您不想重复数据,则可以使用union ,如下所示:

SELECT * FROM
(SELECT * FROM TableA 
UNION
SELECT * FROM TableB) t
WHERE engine_type = 'some value';
SELECT * FROM Table A

INTERSECT

SELECT * FROM TABLE B

THIS CODE GIVES YOU ROWS WITH COMMON DATA IN BOTH COLUMNS此代码在两列中为您提供具有公共数据的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接具有相同列名但数据缩写不同的两个表 - Joining two tables with same column names but with different data abbreviations 连接具有相同数据但具有不同列名的表 - Joining Tables with the Same Data But Different Column Names 来自具有相同列名的两个表的数据 - Data from two tables with same column names SQL 如何连接SQL中列名相同但数据不同的两个表 - SQL how to join two tables with same column names but different data in SQL 如何在Oracle中从具有相同列名的两个表中检索数据 - How to retrieve data from two tables with same column names in oracle 如何从列名相同的两个表中检索数据 - How to retrieve data from two tables whose column names are the same 当公共列具有不同的名称但两个表中的信息相同时,如何连接两个sql表 - How to join two sql tables when the common column has different names but information is the same in both tables 连接具有不同列名和相同行的两个表 - Join two tables with different column names and same rows SQL查询包含相同数据的具有不同列名的多个表 - SQL query multiple tables with different column names that contain the same data 如何在asp.net中显示带有两个具有相同列名但具有不同值的表的图表C# - how to show chart in asp.net with two tables with same column names but with different values in it C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM