如何在选择查询中区分两个表的相同字段名称? [英] How to differentiate between same field names of two tables in a select query?

查看:237
本文介绍了如何在选择查询中区分两个表的相同字段名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有两个以上的表,它们都包含相同的字段名,例如

I have more than two tables in my database and all of them contains same field names like

table A           table B       table C
field1            field1        field1
field2            field2        field2
field3            field3        field3
.                 .             .
.                 .             .
.                 .             .
.                 .             .

我必须编写一个SELECT查询,该查询从这3个表中获取几乎所有相同的字段.我正在使用类似这样的东西:

I have to write a SELECT query which gets almost all same fields from these 3 tables. I am using something like this :

select a.field1,a.field2,a.field3,b.field1,b.field2,b.field3,c.field1,c.field2,c.field3 from table A as a, table B as b,table C as c where so and so.

但是当我打印field1的值时,它给了我最后的表格值.

but when I print field1's value it gives me the last table values.

如何获取具有相同字段名称的三个表的所有值?我必须为每个表编写单个查询,还是有任何方法可以在单个查询中获取所有查询?

How can I get all the values of three tables with the same field names? do I have to write individual query for every table OR there is any ways of fetching them all in a single query?

推荐答案

就像这样写,

select a.field1 as af1,a.field2 as af2,a.field3 as af3,b.field1 as bf1,b.field2 as bf2,b.field3 as bf3,c.field1 as cf1,c.field2 as cf2,c.field3 as cf3 from table A as a, table B as b,table C as c where so and so.

这篇关于如何在选择查询中区分两个表的相同字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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