views:

149

answers:

3

In MySQL, you can use the keyword USING in a join when you join on columns from different tables with the same name. For example, these queries yield the same result:

SELECT * FROM user INNER JOIN perm USING (uid)
SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid

Is there an equivalent shortcut in SQL Server?

+10  A: 

nope, have to use:

SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid
KM
+4  A: 

No, SQL Server does not support this kind of shortcut.

I would like to point out that even if it did, shortcuts like these are NOT A GOOD IDEA. I recently worked on a database where the developers thought it would be a good idea to use the *= and =* shortcuts for RIGHT JOIN and LEFT JOIN. Good idea until someone upgraded the SQL Compatibility level to 90. Then it became an extremely Bad Idea.

So, learn from us. Shortcuts are bad. A little extra typing never killed anyone.

Boo
Did you mean `*=` and `=*`? SO uses asterisks for formatting.
Matt Solnit
Yes, I meant *= and =* - Thanks Matt
Boo
+1  A: 

Also, I would add not to use wild characters, "*" in your select statement - explicitly specify the column name.

True but I was just going for a short query to exemplify the use of USING. The SELECT details here are irrelevant.
Dinah