Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.