Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Delete

$
0
0
Code:

SQL> select * from employee;

LASTNAME            DEPARTMENTID
-------------------- ------------
Rafferty                      31
Jones                          33
Steinberg                      33
Robinson                      34
Smith                          34
John

6 rows selected.

SQL> select * from department;

DEPARTMENTID DEPARTMENTNAME
------------ --------------------
          31 Sales
          33 Engineering
          34 Clerical
          35 Marketing

SQL> select * from department d join employee e
  2  using (departmentid);

DEPARTMENTID DEPARTMENTNAME      LASTNAME
------------ -------------------- --------------------
          31 Sales                Rafferty
          33 Engineering          Jones
          33 Engineering          Steinberg
          34 Clerical            Robinson
          34 Clerical            Smith

SQL> delete from employee e
  2  where exists ( select * from department d join employee e
  3                using (departmentid));

6 rows deleted.

.


In the above structure, table EMPLOYEE contains NULL value in the departmentid column which refers the lastname of JOHN.

when i delete EMPLOYEE table joining DEPARTMENT table using EXISTS, even the NULL value is also getting deleted .But i want JOHN record to be present while delting...I cant understand what mistake i did.

Can anyone help me getting the right query.

Viewing all articles
Browse latest Browse all 13329

Trending Articles