我在 mysql 数据库中有 2 个表存储和共享。我试图避免使用 IN 子句。请参阅下文了解更多详情
select id, user_id from stores where user_id =7;
+----+---------+
| id | user_id |
+----+---------+
| 36 | 7 |
| 37 | 7 |
select stores_id,share_id from shares where share_id=7;
+-----------+----------+
| stores_id | share_id |
+-----------+----------+
| 15 | 7 |
| 38 | 7 |
现在我运行这个
SELECT stores.id
FROM stores
WHERE user_id = 7
UNION
(SELECT stores.id
FROM stores
WHERE id IN (SELECT stores_id
FROM shares
WHERE share_id = 7));
要获得以下结果:
+----+
| id |
+----+
| 36 |
| 37 |
| 15 |
| 38 |
+----+
问题 如何重写查询,以便不使用 IN关键字。?