开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜