我有三个表:calls,attachments和notes。我想显示calls表中的所有内容,并显示呼叫是否有附件和笔记-通过确定其中是否存在具有call_id的附件或笔记记录来实现。可能有笔记和附件,也可能没有,但我需要知道。
表结构:
calls:
call_id | title | description
附件:
attach_id | attach_name | call_id
注:
note_id | note_text | call_id
如果我写:
SELECT c.call_id
, title
, description
, count(attach_id)
FROM calls c
LEFT JOIN attachments a ON c.call_id = a.call_id
GROUP BY c.call_id
, title
, description
给我一个列表,其中包括所有电话的呼叫和附件数量。
我如何添加一列显示注释的数量或指示存在注释的列?
有什么想法吗?
谢谢。
*
在exists()
语句中,速度会更快,不是吗? - Robert Koritnik