De Vonte De Vonte - 3 months ago 7
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

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

UPDATE A
SET A.item  = B.itemA + ' - ' + B.itemB 
   ,A.temp  = B.itemA 
FROM tableA A 
INNER JOIN tableB B ON A.[sid] = B.sItemId 
where B.id = 1