-1

I have this SQL query:

select concept, count(*)
from annotation
where exists (select 1
              from annotation a2
              where a2.comment_commentid = annotation.comment_commentid and a2.concept = 'Fatigue'
             )
group by concept;

And I want to replace 'Fatigue' with {{word}}, to do a filter widget, maping to the column from database. I have the following error:

ERROR: syntax error at or near "=" Position: 307

What I need to change to aplly the filter? selecting the available words from that column? With variable type as Text it works... But don't display all the available options, in filter, as variable type Field Filter do...

Thanks!

eshirvana
  • 23,227
  • 3
  • 22
  • 38

1 Answers1

0

The outer annotation table needs an alias too. When in doubt, the inner scope always prevails whern resolving names, and the inner exists(...) query an an annotation name in scope, too)

[And the cause of your error is probably that the middleware gets confused]


select concept, count(*)
from annotation a1 -- <<-- HERE!
where exists (select 1
              from annotation a2
              where a2.comment_commentid = a1.comment_commentid and a2.concept = 'Fatigue'
             )
group by concept;
wildplasser
  • 43,142
  • 8
  • 66
  • 109
  • not working on sql question... give this error: ```ERROR: invalid reference to FROM-clause entry for table "annotation" Hint: Perhaps you meant to reference the table alias "a1". Position: 221``` – Renato Santos Apr 11 '21 at 21:37
  • `Perhaps you meant to reference the table alias "a1".` <<-- makes sense – wildplasser Apr 12 '21 at 15:03