Rating:

**Task:** The regional manager for the El Paso branch of De Monne Financial is afraid his customers might be targeted for further attacks. He would like you to find out the dollar value of all outstanding loan balances issued by employees who live in El Paso. Submit the flag as flag{$#,###.##}.

We need a query to select from one table based on a column value in other table.

**alternative 1 : inner join**
```sql
select
A.*
from
loans A
inner join employees B
on A.employee_id = B.employee_id
where
B.city = 'El Paso';
```

**alternative 2: correlated sub select**

```sql
select
A.*
from
loans A
where
A.employee_id in (
select B.employee_id from employees B where B.city = 'El Paso'
)
```

The alternative 1 is faster in caluclation time for me.

**Final sum of loans:**
```sql
select sum(A.balance) from loans A inner join employees B on A.employee_id = B.employee_id where B.city = 'El Paso';
```

Original writeup (https://github.com/hhassen/writeup_deadface_2021/blob/main/sql.md).