I have the following sample tables:
EMPLOYEE
employee_id
first_name
last_name
INDEX on PRIMARY
TIMESHEET
timesheet_id
employee_id
hours
INDEX on PRIMARY
INDEX on employee_id name FKEY_EmpID
I want to run a query with a sub select to get all the hours for each
employee.
I have the following
SELECT t.hours, e.first_name, e.last_name
FROM timesheet t, employee e
WHERE t.employee_id in
(
SELECT employee_id FROM employee
)
AND t.employee_id = e.employee_id
GROUP BY t.employee_id
When I run explain on this, I get...
ID: 1
Select_Type: PRIMARY
table: t
type: ALL
possible_keys: FKEY_EmpID (what I named it)
key: <NULL>
key_len: <NULL>
rows: 126592
Extra: Using where; Using temporary; Using filesort
ID: 1
Select_Type: PRIMARY
table: e
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
rows: 1
Extra: Using where;
ID: 2
Select_Type: DEPENDENT SUBQUERY
table: employee
type: unique_subquery
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
rows: 1
Extra: Using index
I'm trying to not have it scan the full timesheet table. Is there
something simple I'm missing?
TIA,
Don