mykey
conflictingTo solve the problem you explicitely ask for in your question ("Why does it give me a syntax error?"), @Alex Poole's comment is the answer: GO
is not Oracle, just remove it.
But then you will get what Krzysztof Madejski's answers for:
the USING
will work as long as the join column (mykey
) is the only column which has the same name over multiple tables:
create table Temptable as
SELECT *
FROM
table_1
INNER JOIN table_2 USING (mykey)
INNER JOIN table_3 USING (mykey)
WHERE table_1.A_FIELD = 'Some Selection';
If you've got other columns with a duplicate name over two tables, you'll have to first make them unique:
create table table_3_r as select *, col as col3 from table_3; alter table table_3_r drop column col; /* And do the SELECT on table_3_r instead of table_3 */; drop table table_3_r;
PIVOT
:PIVOT
requires you to tell which values of the pivot column can generate a pseudo-column, one just have to list 0 values to get 0 column.PIVOT
wayWITH table_3_r as (SELECT * FROM table_3 PIVOT (max(1) FOR (a_field) IN ()))
SELECT *
FROM
table_1
INNER JOIN table_2 USING (mykey)
INNER JOIN table_3_r USING (mykey)
WHERE table_1.A_FIELD = 'Some Selection';