Skip to content
Advertisement

Postgresql – Select in Select Alias Problem

I have query.

https://dbfiddle.uk/?rdbms=postgres_12&fiddle=1b3a39357a5fe028f57b9ac26d147a1d

I am getting below error:

[42703] ERROR: column “bonus_ids” does not exist Hint: Perhaps you meant to reference the column “bonuses.bonus_id”.

How can I use correctly this query?

Advertisement

Answer

I think you are looking for lateral joins. Your example is too contrieved to really make sense, but the logic is:

As opposed to when using inline subqueries, you can refer to columns from one subquery within the next one – as shown in the where clause of the second subquery.

Note that you want to use any() rather than in to check if a value belongs to an array.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement