Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Using a CTE with = ANY

Query:

WITH first_names AS (SELECT DISTINCT fname FROM voters) 
SELECT name 
from nicknames 
WHERE groupi = (
    SELECT nn.groupi 
    FROM nicknames AS nn 
    WHERE name = 'john'
) AND name != 'john' AND upper(name) = ANY(first_names);

Error: column "first_names" does not exist

How do I make an array from a select and use it in a where statement?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

try JOIN instead of ANY

WITH first_names AS (SELECT DISTINCT fname FROM voters) 
SELECT name 
from nicknames 
JOIN first_names on fname = upper(name)
WHERE groupi = (SELECT nn.groupi FROM nicknames AS nn WHERE name = 'john') AND name != 'john' 
;
over 4 years ago · Santiago Trujillo Report

0

You're confusing auxiliary statement names with columns here. first_names is the name for the result provided by your SELECT DISTINCT, and fname is the name of the column contained within.

Not commenting on the correctness of your query overall, the corrected statement would be to use the correct column name.

WITH first_names AS (SELECT DISTINCT fname
                     FROM voters)
SELECT name
FROM nicknames
WHERE groupi = (
  SELECT nn.groupi
  FROM nicknames AS nn
  WHERE name = 'john'
) AND name != 'john' AND upper(name) = ANY (first_names.fname);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!