英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论