我有以下表结构:
OwnerId - PKey
ActionListId - FKey
ActionListId - PKey
Actions - VARCHAR(8000)
ActionId - PKey
ActionList.Actions的格式如下:
ActionId1, ActionId2, ActionId3, ActionId4, ... ActionIdN
我正在尝试执行此查询:
select
o.*,
a.Name
from Owner as o
join ActionList as al on al.ActionListId = o.ActionListId
join Action as a on a.ActionId in (al.Actions)
where o.OwnerId = 1;
但是我收到了一条记录。为什么第二个连接没有成功加入整个数组而只是第一个元素?有没有办法通过一个查询获取ActionList中的所有动作?
答案 0 :(得分:0)
试试这个
SELECT O.*,A.Name
FROM Owner AS O
LEFT JOIN ActionList AS AL ON
AL.ActionListId = O.ActionListId
LEFT JOIN Action AS A ON
A.ACtionID IN (SELECT ACTIONS FROM ACTIONList)
WGERE O.OwnerId = 1;