snippetMinor
How do I do a JOIN in ANSI SQL 89 syntax?
Viewed 0 times
sqljoinsyntaxansihow
Problem
In Oracle, I use
where the dots represent either the type of join or the condition on which to be joined.
Is this ANSI 89 syntax? If not, then how would I perform a join if I were using ANSI 89?
SELECT * FROM table1...JOIN...where the dots represent either the type of join or the condition on which to be joined.
Is this ANSI 89 syntax? If not, then how would I perform a join if I were using ANSI 89?
Solution
You don't want to use SQL-89 syntax. SQL-89 is just an implicit
Is the same as the more modern
Adding the
You want to use SQL-92 Syntax.
Or even better (if the join column is the same and it's an equijoin
See also
CROSS JOIN (Cartesian product).SELECT * -- NEVER
FROM foo, bar; -- NEVER EVER DO THISIs the same as the more modern
SELECT *
FROM foo
CROSS JOIN bar;Adding the
WHERE clause makes it the equivalent of an INNER JOIN ... ONSELECT * -- DO NOT
FROM foo,bar -- DO THIS
WHERE foo.foo_id = bar.foo_id; -- EVERYou want to use SQL-92 Syntax.
SELECT *
FROM foo
INNER JOIN bar
ON foo.foo_id = bar.foo_id;Or even better (if the join column is the same and it's an equijoin
=)SELECT *
FROM foo
INNER JOIN bar
USING (foo_id);- Note some people don't use
INNER. That's fine. It's still SQL-92.
See also
- What does [FROM x, y] mean in Postgres?
Code Snippets
SELECT * -- NEVER
FROM foo, bar; -- NEVER EVER DO THISSELECT *
FROM foo
CROSS JOIN bar;SELECT * -- DO NOT
FROM foo,bar -- DO THIS
WHERE foo.foo_id = bar.foo_id; -- EVERSELECT *
FROM foo
INNER JOIN bar
ON foo.foo_id = bar.foo_id;SELECT *
FROM foo
INNER JOIN bar
USING (foo_id);Context
StackExchange Database Administrators Q#212200, answer score: 8
Revisions (0)
No revisions yet.