Forum Discussion

Neha11's avatar
Neha11
Copper Contributor
Mar 08, 2022

Lead function error

Hi,
I have lead function after on clause as one of the conditions in join
Gives an error to me as "misuse of window function lead()"

Pls help
  • Neha11 , a Windows function like LEAD is a post operation, you can not use it in a JOIN condition or in a WHERE clause, only in the SELECT clause.

     

    One way round is to use a CTE = Common Table Expression to re-use the query result.

     

    Olaf

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    Neha11 , a Windows function like LEAD is a post operation, you can not use it in a JOIN condition or in a WHERE clause, only in the SELECT clause.

     

    One way round is to use a CTE = Common Table Expression to re-use the query result.

     

    Olaf

Resources