logoalt Hacker News

zabzonktoday at 10:29 AM2 repliesview on HN

> doing JOINs with the USING clause

I'm ashamed to say that despite using SQL from the late 1980s, and as someone that likes reading manuals and text books, I'd never come across USING. Probably a bit late for me now to use it (or not) :-(


Replies

tkejsertoday at 11:17 AM

I didn't really write USING in anger until around 10 years ago, and I have been around a long time too.

Not all databases support it. But once you start using it (pun) - a lot of naming conventions snap into place.

It has some funky semantics you should be aware of. Consider this:

``` CREATE TABLE foo (x INT);

CREATE TABLE bar (x INT);

SELECT * FROM foo JOIN bar USING (x);

```

There is only one `x` in the above `SELECT *` - the automatically disambiguated one. Which is typically want you want.

n4r9today at 11:13 AM

I've used SQL for around a decade and also never came across it. I'm maintaining SQL code with hundreds if not thousands of basic primary key joins and this could make those queries way more concise. Now I want to know the reasons for not using USING!

show 1 reply