Hope you are having a great day. I came across a problem.
In database the use of distinct is not efficient and it poses numerous timeout problems.
So In a simple case I have...
select distinct first_value(e.error_message) over (order by create_date desc)
from database e
Which exactly one result which error message is ordered by latest and it is the first value of its kind, now when I run it it takes about .8 seconds which isn't bad, but the problem is, joining and making this query bigger and doing more than just retrieving errors will be a problem.
So if I do the following query...
select first_value(e.error_message) over (order by create_date desc)
from database e
this query takes about .4 seconds, but the problem is only want the first item that is given. How do I do this, I do not know the row number that is specific with it.
Thanks everyone.
*EDIT
Just to let everyone know, using Rob's solution has made my huge query more efficient TRY NOT TO USE DISTINCT WHEN POSSIBLE!!!!