Jump to content

Can this be made more efficient


AdRock

Recommended Posts

I have a few queries and want to know if they can be made more efficient

 

Here is an example query

 

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 a.ssn
                   FROM Employee a
                   INNER JOIN Works w ON w.ssn = a.ssn
            INNER JOIN Department d ON d.dno = w.dno
            WHERE d.dname = 'Personnel'); 

Here is the table structures. As you can see there is no direct relation between any of the tables so I have an extra table with foreign keys for ssn and dno called Works (employee and departement) and a table with foreign keys for ssn and name called Children (employee and child)

 

Employee

--------

ssn int(2) primary key

phone varchar (20) not null

salary int(2)

 

Department

--------

dno int(1) primary key

dname varchar(20) not null

budget int(6)

 

Child

--------

name varchar(20) unique

age int(2) not null

Link to comment
Share on other sites

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.