多个相同名称的SQL选择列 [英] SQL select column when there's more than one of the same name

查看:101
本文介绍了多个相同名称的SQL选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询

select *
from alldistros t1
LEFT join origin t2 on t1.name=t2.name
LEFT join desktop t3 on t2.name=t3.name
LEFT join beginnerdistributions t4 on t3.name=t4.name

它加在我所有的桌子上。但是现在,当我要选择名称字段(所有字段都包含在内)时,我无法显示它。当我打电话时它只是空白。而且我会这么想,因为存在多个同名的列。

it add on all my tables. But now when I want to select the name field (which is in all of them) I can't show it. It's just blank when I call it. And I would think so since there's more than 1 columns of the same name.

我该怎么办才能解决此问题?

What can I do to fix this?

纯联接将不起作用,因为它会删除其他表中没有属性的某些字段。

Just a plain join won't work, since it removes some of the fields that does not have the properties in the other tables.

推荐答案

您可以使用 AS关键字来命名列。例如:

You can use the 'AS' keyword to name a column. For instance:

select t1.name AS DistroName, t2.name AS OriginName, t3.name AS DesktopName
from alldistros t1
LEFT join origin t2 on t1.name=t2.name
LEFT join desktop t3 on t2.name=t3.name
LEFT join beginnerdistributions t4 on t3.name=t4.name

这篇关于多个相同名称的SQL选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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