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
https://forums.phpfreaks.com/topic/78004-can-this-be-made-more-efficient/
Share on other sites

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.