De Vonte De Vonte - 1 year ago 88
SQL Question

Is there a more efficient query I can use

I want to know if theres a better way to script out this update statement:

update table A
set item = (select itemA + ' - ' + itemB from table B where id = 1),
temp = (select itemA from table B where id = 1)
where sid = (select sItemId from table B where id = 1)

Answer Source

Use JOINS to make it more efficient and Alias to make it more readable.

SET A.item  = B.itemA + ' - ' + B.itemB 
   ,A.temp  = B.itemA 
FROM tableA A 
INNER JOIN tableB B ON A.[sid] = B.sItemId 
where = 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download