0

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
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
user2393171
  • 365
  • 1
  • 3
  • 6

3 Answers3

3

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.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
Kris Gruttemeyer
  • 872
  • 7
  • 19
3

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.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
0

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

Mike Cheel
  • 12,626
  • 10
  • 72
  • 101