我有以下两个表:
Users
+----+-----------+
| id | user_name |
+----+-----------+
| 18 | Andrei |
| 19 | Gicu |
| 20 | Gigel |
+----+-----------+
Requests
+----+-----------+---------+
| id | from_user | to_user |
+----+-----------+---------+
| 3 | 18 | 19 |
| 4 | 18 | 20 |
| 5 | 20 | 19 |
+----+-----------+---------+
我需要进行以下查询:
SELECT requests.from_user
FROM requests
WHERE
(SELECT id FROM users WHERE users.user_name='Gicu')=requests.to_user;
返回:
+-----------+
| from_user |
+-----------+
| 18 |
| 20 |
+-----------+
我的问题是如何获取与这些id(18和20)相关联的用户名?我应该在查询中添加什么?(我不熟悉连接/联合和其他东西)