int 21
我想获取附加到实体的文件和文件夹列表。尝试过以下查询,但如果文件夹或文件中没有记录,它会给出空记录
CREATE TABLE link (
entityid integer,
fileid INT (11) NULL,
folderid INT (11) NULL
);
CREATE TABLE file (
fileid integer,
name varchar
);
CREATE TABLE folder (
folderid integer,
name varchar
);
示例数据
select fi.name,fo.name
FROM link ll
LEFT OUTER JOIN file fi ON lk.FileId = fi.FileId
LEFT OUTER JOIN folder fo ON lk.FileId = fo.FileId
WHERE dl.entityid = 307
答案 0 :(得分:0)
只需将entityid
添加到select子句:
SELECT ll.entityid, fi.name, fo.name
FROM link ll
LEFT OUTER JOIN file fi ON lk.FileId = fi.FileId
LEFT OUTER JOIN folder fo ON lk.FileId = fo.FileId
WHERE dl.entityid = 307;