首页 > 解决方案 > 如何在sql查询中使用exists函数?

问题描述

Select EXISTS (adm.document_id) as documentUploaded, name,customer_id as customerId,
adm.id,document.id as documentId from 
document,application_document_mapping as adm where
document.deleted=false and document.id=adm.document_id and application_id=1;

上面的查询给出了一个语法错误。无法理解为什么?

标签: sqlpostgresql

解决方案


下面是一种方法

 select t1.* from table document t1
 where exists ( select 1 from application_document_mapping t2 where
                                      t1.id=t2.document_id 
                                      and application_id=1)

推荐阅读