postgresql - Postgres SQL - Column does not exist -


this question has answer here:

select nmemail order_email,         dtorder,         vlorder,         cohorts.cohortdate    factorderline         join (select nmemail cohort_email, min(dtorder) cohortdate  factorderline group  cohort_email limit 5) cohorts  on order_email= cohort_email limit 5;  

error: column "order_email" not exist

what problem query?

the problem definition of column alias hasn't been parsed @ time join evaluated; use actual column name instead:

select nmemail order_email,         dtorder,         vlorder,         cohorts.cohortdate    factorderline  join (   select nmemail cohort_email, min(dtorder) cohortdate     factorderline    group cohort_email limit 5 ) cohorts on nmemail = cohort_email  limit 5;  

also, when using limit, should use order by clause.

from docs:

when using limit, important use order clause constrains result rows unique order. otherwise unpredictable subset of query's rows.


Comments