0

This Q&A shows how to use USING() in Mysql to join two tables on columns that are called the same thing in both tables. The advantages are (1) not having to repeatedly specify source tables and (2) no ambiguity in the resulting SELECT statement when referring to the columns used to join.

I'd like to do that in SQL Server, but I get the warning:

'USING' is not a recognized built-in function name.

Is there a way I can do that in SQL Server? I want this:

SELECT * FROM t1
LEFT JOIN t2 USING (a, b, c)

Not this:

SELECT * FROM t1
LEFT JOIN t2 ON t1.a = t2.a AND t1.b = t2.b AND t1.c = t2.c
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
  • 1
    No, that is not valid syntax for SQL Server t-sql. – squillman Oct 14 '21 at 15:47
  • 1
    No, this is not supported in SQL Server, and imho that's the right choice, automatic joins based on column names is a recipe for errors. – Stu Oct 14 '21 at 15:48
  • If there's no alternative to typing `t1.a = t2.a AND t1.b = t2.b ...` then bummer, but I guess that may be an/the answer to the question - feel free to post it as such. – Sam Firke Oct 14 '21 at 15:49

0 Answers0