user2393171
user2393171

Reputation: 393

Natural Join in related table

I have to use only to use natural join it is not working in sql server,,, i have to select EmpName,EmpDOB and EMPDOB from employee table and just DEPTID from department table..please help

SELECT     DEPARTMENT.DEPTID, EMPLOYEE.EmpID, EMPLOYEE.EMPName, EMPLOYEE.EMPDOB
FROM         DEPARTMENT NATURAL JOIN
                      EMPLOYEE ON DEPARTMENT.DEPTID = EMPLOYEE.DEPTID

Upvotes: 0

Views: 472

Answers (3)

Kris Gruttemeyer
Kris Gruttemeyer

Reputation: 872

If you must use a NATURAL JOIN then try this:

SELECT D.DEPTID, E.EmpID, E.EMPName, E.EMPDOB
FROM DEPARTMENT D NATURAL JOIN EMPLOYEE E

As long as the column names DEPTID are the SAME on both tables. NATURAL JOIN Doesn't need to specify what fields are joined, it figures it out on it's own.

Here's a great reference on the NATURAL JOIN: http://www.w3resource.com/sql/joins/natural-join.php

The Natural Join won't work in SQL-Server though, only in MySQL.

Upvotes: 3

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115590

SQL-Server has not implemented NATURAL JOIN.

If you want to experiment with its use, try Oracle or Postgres or MySQL. You can also use SQLfiddle.com if you are not allowed to install them.

Upvotes: 3

Mike Cheel
Mike Cheel

Reputation: 13106

When you use the '=' sign it is just a normal equi-join (explicit) while a natural join the predicates are figured out by the query engine (implicit). http://en.wikipedia.org/wiki/Join_(SQL)#Natural_join

Upvotes: 0

Related Questions