开发者

How to get common field in ten tables with different field name

开发者 https://www.devze.com 2022-12-26 08:16 出处:网络
I am having a common field in ten tables with different field name. example: table1: t1_id   t1_location

I am having a common field in ten tables with different field name.

example:

table1:

t1_id     t1_location

1         india

2         china

3         america

table2:

t2_id     t2_location

4         london

5         australia

6     开发者_如何学JAVA     america

Now my o/p should be:

location

india

china

america

london

australia

How should i get that using mysql query.

thanks in advance


You can query the locations using UNION, which will also remove duplicates:

Select t1_location As location
From table_1
Union
Select t2_location As location
From table_2

Sounds like it would be a better approach to store all locations in a separate table with ID, and refer to that IDs in your tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消