NATURAL JOIN Syntax

566 Views Asked by At
SELECT*
FROM student NATURAL JOIN teaches

17:16:44 FAILED [SELECT* - 0 rows, 0.023 secs] [Code: 102, SQL State: 42000] Falsche Syntax in der Nähe von "teaches".

I really don't see the Syntax Error, what Problem could this be? Thanks in advance!

1

There are 1 best solutions below

2
Gordon Linoff On

Just don't use natural join. Apparently, you have a database that doesn't support it. So, use explicit join syntax:

SELECT . . . 
FROM student s INNER JOIN
     teaches t
     ON s.studentId = t.studentId;  -- I'm guessing what the keys are

The main problem with NATURAL JOIN is that it uses columns with the same name, rather than properly declared foreign key relationships. The secondary problems are that the keys are not in the query -- making problems hard to debug. Unexpected keys could be used for the join, and you can't even see what they are. Be explicit on the keys you are using, by including them in an ON or USING clause.