Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
74 views
in Technique[技术] by (71.8m points)

sql - 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

Table B: time, brand, model, color, engine_model

engine_type and engine_model has the same data in reality, but column name's are different

I would like to search certain engine_type or engine_model on both tables and show results. How can I do it?

question from:https://stackoverflow.com/questions/65623203/how-to-search-same-data-on-two-different-tables-with-same-column-names

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use a union query:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...