Why is a UDF so much slower than a subquery?

前端 未结 4 1456
臣服心动
臣服心动 2020-11-28 12:03

I have a case where I need to translate (lookup) several values from the same table. The first way I wrote it, was using subqueries:

SELECT
    (SELECT id FRO         


        
4条回答
  •  旧时难觅i
    2020-11-28 12:37

    To get the same result (NULL if user is deleted or not active).

     select 
        u1.id as creator,
        u2.id as updater,
        u3.id as owner,
        [a.name]
     FROM asset a
            LEFT JOIN user u1 ON (u1.user_pk = a.created_by AND u1.active=1) 
            LEFT JOIN user u2 ON (u2.user_pk = a.created_by AND u2.active=1) 
            LEFT JOIN user u3 ON (u3.user_pk = a.created_by AND u3.active=1) 
    

提交回复
热议问题