AdRock Posted November 20, 2007 Share Posted November 20, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted November 20, 2007 Share Posted November 20, 2007 Unlikely... that's not a correlated subquery (check EXPLAIN), so it's equivalent to using a derived table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.