Jump to content

[SOLVED] Joining 2 working queries together to make 1 query


AdRock

Recommended Posts

I have 2 working queries which both work fine on their own but when i join them together it causes an error

 

What it is supposed to do is select the childrens names whose parents woek in the Presonnel department

 

This is the joined query that causes the problem

 

SELECT chd.name, chdn.ssn as ssn

FROM Child chd

INNER JOIN Children chdn ON chdn.name = chd.name

INNER JOIN Employee e ON chdn.ssn = e.ssn

WHERE chdn.ssn IN (SELECT Employee.ssn, d.dname

FROM Employee

INNER JOIN Works w ON w.ssn = Employee.ssn

INNER JOIN Department d ON d.dno = w.dno

WHERE d.dname = 'Personnel');

 

This is the first query that finds the people who works in the Personnel department and it works

SELECT Employee.ssn, d.dname

FROM Employee

INNER JOIN Works w ON w.ssn = Employee.ssn

INNER JOIN Department d ON d.dno = w.dno

WHERE d.dname = 'Personnel';

 

and the query that lists the childrens name by an employee

SELECT chd.name, chdn.ssn as ssn

FROM Child chd

INNER JOIN Children chdn ON chdn.name = chd.name

INNER JOIN Employee e ON chdn.ssn = e.ssn

WHERE chdn.ssn = 10254;

 

i wanto to replace the chdn.ssn with the other query like i tried above but it's throwing up and error at the second select statement

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.