gpt4 book ai didi

MySQL 子查询 IN 多个值

转载 作者:行者123 更新时间:2023-11-29 06:46:23 25 4
gpt4 key购买 nike

我有 2 张 table :

表格报告

id   |  name
-------------
1 | test 1
2 | test 2
3 | test 3

表reports_access

id_table  |   group_id
-----------------------
1 | 1
1 | 2
1 | 3
1 | 4
2 | 1
2 | 2

我需要根据登录用户的group_id访问报告,一个用户属于多个组。

我尝试过:

SELECT reports.*
FROM reports
WHERE (
SELECT group_id
FROM reports_access AS repacc
WHERE repacc.id_table = reports.id
) IN (1, 3)

我收到此错误:

Subquery returns more than 1 row

我不明白我是否可以使用一个请求来做我想做的事情,因为我需要测试一个数组是否属于另一个数组。

我错过了什么吗?

最佳答案

我认为您正在寻找这个:

 SELECT reports.*
FROM reports
WHERE id in (
SELECT repacc.id_table
FROM reports_access
where group_id
IN (1, 3) )

关于MySQL 子查询 IN 多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49243733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com