Is this the correct way of writing three natu开发者_StackOverflow社区ral joins? :
SELECT C.name, P.name
FROM client C NATURAL JOIN order O NATURAL JOIN product P
WHERE O.date > '15.02.2011'
This is indeed the typical syntax for natural joins. However, not all databases support natural joins (for instance, I don't believe SQLServer supports it) and I don't believe there is an ANSI standard for natural join.
Note that natural joins are generally considered dangerous and something to be avoided - this is because they obscure the join relationship that a query depends on, and could result in queries whose meaning changes if the data model is altered.
To check syntax when your SQL product of choice does not support it, use the Mimer SQL-92 validator. You should discover that order
and date
are reserved words. Change them to my_order
and my_date
respectively and you will then discover yours is valid Transitional SQL-92 syntax.
using this syntax is considered dangerous as it was already mentioned. Consider the following example: T1(id, name, age) T2(id, age, city)
SELECT T1.id, T1.name, T1.age, T2.age
FROM T1 NATURAL JOIN T2
Which column should be used for join? id or age? It is not defined. Every vendor can implement his own way to solving such problems.
Instead of this syntax, consider using traditional join syntax:
SELECT T1.....
FROM T1 INNER JOIN T2 on T1.id=T2.id
精彩评论