多个相同名称的SQL选择列

编程入门 行业动态 更新时间:2024-10-25 09:39:25
本文介绍了多个相同名称的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选择列

本文发布于:2023-10-30 19:00:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543721.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   名称   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!