Issue with subquery - All expressions must have explicit name

gfuller40 picture gfuller40 · Sep 9, 2013 · Viewed 34.5k times · Source

Not sure what is going on here and why this is not working. I'm receiving the following error:

"All expressions in a derived table must have an explicit name" - working with teradata.

    select clm.c_clm
    ,clm.c_loc
    from 
    (select *
    from pearl_p.TLTC900_CLM clm) as cl
    left join
    (select 
    max(av.d_usr_udt_lst)
    from pearl_p.TLTC913_AVY av
    group by 1) as avy
    on cl.i_sys_clm = avy.i_sys_clm

Answer

Derek Kromm picture Derek Kromm · Sep 9, 2013

Your max(av.d_usr_udt_lst) in your subquery doesn't have an explicit name. You need to alias it like this:

max(av.d_usr_udt_lst) as "MaxThing"

So the query looks like

select clm.c_clm
    ,clm.c_loc
    from 
    (select *
    from pearl_p.TLTC900_CLM clm) as cl
    left join
    (select 
    max(av.d_usr_udt_lst) as "MaxThing"
    from pearl_p.TLTC913_AVY av
    group by 1) as avy
    on cl.i_sys_clm = avy.i_sys_clm