View Single Post

   
  #1 (permalink)  
Old 05-10-2008, 02:03 PM
=?ISO-8859-1?B?QW5kcukgSORuc2Vs?=
 
Posts: n/a
Default Alias of scalar subquery

Hi,

is there a way I can rewrite this to avoid the double subquery?

UPDATE the_table AS outer_table SET
parent_id = (SELECT id FROM (SELECT * FROM the_table) AS inner_table
WHERE inner_table.number = outer_table.parent_number),
changed_flag = 1
WHERE outer_table.parent_id != (SELECT id FROM (SELECT * FROM
the_table) AS inner_table WHERE inner_table.number =
outer_table.parent_number)

Note that the two suqueries are absolutely identical.

BTW: Certainly this is a problem of clarity but is it also a problem
of performance or is the subquery cached?

Regards,
André
Reply With Quote