Tags: sql 

Rating: 5.0

We believe Lucia is trying to target a student taught by her SOCI424 professor. How many students were taught by that professor in either term? Submit the number of students as well as the professor's first and last name concatenated.

Now assuming that you have restored the DB from the dump given.

Give a look at ER to understand the joins between tables(i've used dBeaver):
![img](https://i.imgur.com/6uyXLG2.png)

So let's see how many Lucia has taken that course:
```
SELECT u.*
FROM
courses c
INNER JOIN term_courses tc ON c.course_id = tc.course_id
INNER JOIN enrollments e ON tc.term_crs_id = e.term_crs_id
INNER JOIN users u ON e.user_id = u.user_id
WHERE
title = 'SOCI424'
AND `first` = 'Lucia'
```

Luckily just one: luchav1987 LUCIA HAVRON

Then we can also find the teacher adding a table:
```
SELECT instructor.*
FROM
courses c
INNER JOIN term_courses tc ON c.course_id = tc.course_id
INNER JOIN enrollments e ON tc.term_crs_id = e.term_crs_id
INNER JOIN users u ON e.user_id = u.user_id
INNER JOIN users instructor ON tc.instructor = instructor.user_id
WHERE
title = 'SOCI424'
AND u.`first` = 'Lucia'
```

Here we go, half of the flag is done: CLAUDE DARRACOTT

Now thats the other half *How many students were taught by that professor in either term?*

Easily count the users that have enrolled to his courses with this query:
```
SELECT Count(*)
FROM
term_courses tc
INNER JOIN enrollments e ON tc.term_crs_id = e.term_crs_id
WHERE
tc.instructor = 480;
```

And it comes 122

So the flag is **flag{122_ClaudeDarracot}**