Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL join using USING: <column name> is not a recognized table hints option

I have the following JOIN:

SELECT * FROM tableA INNER JOIN tableB USING (commonColumn)

I get an error:

"commonColumn" is not a recognized table hints option. If it is intended as a parameter to a table-valued function or to the CHANGETABLE function, ensure that your database compatibility mode is set to 90.

The following instead works:

SELECT * FROM tableA INNER JOIN tableB ON tableA.commonColumn = tableB.commonColumn

The compatibility level in my case is set to 100 (SQL Server 2008), while, by the way, I am working with SQL Server 2012.

What am I doing wrong? I find it very difficult to find example of the use of the keyword USING, as it is almost impossible to do a relevant web search. Yet, it seems the right thing to use when the "joining columns" have the same name...

like image 818
Antonio Avatar asked Oct 18 '25 01:10

Antonio


2 Answers

USING is not supported SQL Server syntax. It's not a reserved keyword, either, so the query engine is using that as a table alias.

It is an ODBC keyword, but those are handled somewhat differently. The engine won't always complain if you use them, but you're not supposed to use them anyways.

It is also listed as a possible future reserved keyword. It's common for new editions of SQL Server to add words to the core reserved list.

Personally, I don't see them adding NATURAL JOIN syntax support, even with USING. A lot of DBAs consider NATURAL JOINs problematic.

like image 175
Bacon Bits Avatar answered Oct 19 '25 19:10

Bacon Bits


The USING keyword is used to specify the source data for MERGE statements (called <table source>) in the documentation.

like image 24
Cristian Lupascu Avatar answered Oct 19 '25 18:10

Cristian Lupascu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!