用相同名称连接两个列的更简洁方法 SQL

huangapple go评论57阅读模式
英文:

shorter way to join 2 columns with the same name SQL

问题

"LEFT JOIN ON(colname)" 可以用来连接两个具有相同列名的列,而无需同时提及它们的列名,与 "LEFT JOIN ON(a.colname = b.colname)" 不同。你尝试过的 "ON(colname)" 似乎没有起作用。

英文:

I am working with SQL again and recall there being a way to join 2 columns with the same name without mentioning both, the syntax was something like this: LEFT JOIN ON(colname) as opposed to LEFT JOIN ON(a.colname = b.colname) does anyone know the command I'm looking for?

I tried ON(colname) but this didn't work.

答案1

得分: 2

是的,有一种方法只提及列一次,但不是使用 ON 关键字,而是使用 USING 关键字。像这样:

SELECT *
FROM table1
JOIN table2
USING (列名);
英文:

Yes, there is a way to mention the column only once, but that's not with the ON keyword, it's using the USING keyword. Like so:

SELECT *
FROM table1
JOIN table2
USING (columnName);

huangapple
  • 本文由 发表于 2023年5月10日 20:29:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定