Reputation: 10068
Can some one please explain the inner join syntax in the SQL below:
CREATE TABLE dataset AS
SELECT property.id
, amount.band
, amount."value"
FROM property
INNER JOIN (locality INNER JOIN amount ON locality.code = amount.code) ON (property.band = amount.band) AND (property.id = locality."UniqueId")
Why is the table locality
defined before the second inner join? I've never come across such strange syntax.
Is there a more clearer way to right the same query so that someone can easily understand whats going on?
Upvotes: 3
Views: 416
Reputation: 44766
FROM property
INNER JOIN (locality INNER JOIN amount ON locality.code = amount.code)
ON (property.band = amount.band) AND (property.id = amount."UniqueId")
is the same as
FROM property
INNER JOIN amount ON property.band = amount.band AND property.id = amount."UniqueId"
INNER JOIN locality ON locality.code = amount.code
When INNER JOIN
s only, you can re-order them as you want.
(Any specific reason to JOIN locality? You don't select any of its columns. Is it some kind of EXISTS
, or do you want multiple rows returned if there are several matching rows in that table?)
Upvotes: 2