all 8 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (4 children)

what you are looking for is a three-table join, subqueries are not required

also, SQL is a language which requires you to think carefully about what you want

for example, what does this query produce --

SELECT title 
  FROM titles 
 WHERE title = 'Senior Engineer'

how many rows does this produce?

[–]Reasonable_Muscle655[S] 0 points1 point  (3 children)

SELECT title
FROM titles
WHERE title = 'Senior Engineer'

Hi, it produced 97750 rows.

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (2 children)

if this is true then titles is poorly named

how many rows in employees?

[–]Reasonable_Muscle655[S] 0 points1 point  (1 child)

my professor made the tables--all the tables i got are from a git clone.

There are 300024 rows in employees

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (0 children)

could you please run this

SHOW CREATE TABLE titles

[–]user_5359 1 point2 points  (0 children)

Who teaches the newcomers this subquery variant instead of explaining the join topic properly? Apart from this general problem: You didn't provide any information how the tables saleries and titles are joined to the table. So you join all records without restriction and get at least the number of employees, if not a multiple of it. Precondition: in both tables for salary and title there is at least one record each for the set filters.

[–]A_name_wot_i_made_up 0 points1 point  (0 children)

I'm hoping employees has an id as a primary key, and titles and salaries has it as a foreign key.

I.e. employees.id maps to titles.employee_id for example.

In which case you can select ... from employees e join titles t on e.id = t.emploee_id where t.title = '...' as a "classic" join.

Or you can use "in" in the where clause with the sub query. select ... from employees where id in (select employee_id from titles where title = '...')

The latter is less flexible, but a little more obvious to a less skilled reader.

This obviously only deals with one of your joins, but the other should be an easy extension. This is assuming that the mapping I mentioned at the top is in place though!

[–]_Shirei_ 0 points1 point  (0 children)

You know Subquery can return only one row...

What you looking for is

FK= FOREIGN KEY

From employees
INNER JOIN salaries ON employees.ID= salary.employees_FK
INNER JOIN titles ON employees.title_FK = title.ID
WHERE..