Search code examples
sqlpostgresqldataview

PostgreSQL: Why can't I add two MAX to this view


I am trying to create a simple view using the following query:

SELECT 
MAX(row)
,"Email"
,MAX("DateUpdated")

FROM

"Staging"."DuplicateSubscribers"

GROUP BY "Email"

It is throwing the following error:

ERROR: column "max" specified more than once

Can someone explain what I am missing as I have tried this as a query and it worked well.


Solution

  • Try aliasing the selected expressions:

    select MAX(row) as max_row,
        "Email",
        MAX("DateUpdated") as max_dateupdated
    from "Staging"."DuplicateSubscribers"
    group by "Email"