Skip to main content

Outer query column reference in inner query case

  • November 19, 2017
  • 1 reply
  • 7 views

jumanji
Forum|alt.badge.img+1

Hi,
I am trying to write below query

Select *
From a
Where a.country="India" AND
A.language ="Hindi"
AND(case when (spoken = true AND exist(
select 1 from b
where b.country=a.country and
b.language=a.language
AND case when a.population >= b.populatiom)) then
True
Else
false
END)

it is not working, because we can't reference "a.population" outer query field in case expression of innerquery. I tried rewriting it wil OR caluse Vertica is not allowing it.

How can I re-write this

1 reply

jumanji
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 19, 2017

Not sure how to edit original post. Resubmitting the query by fixing the error

Select *
From a
Where a.country="India" AND
A.language ="Hindi"
AND(case when (spoken = true AND exist(
select 1 from b
where b.country=a.country and
b.language=a.language
AND( case when (a.population >= b.population)) then
True
Else
false
END)) then
true
else
false
end)