I want to update table1 with the new minimum price for each specific accountId.
My query below works, I just want to automate it so that I don’t have to copy/paste the accountId for each query.
table1
client accountId price
------------------------
John 1234 5000
Joe 12345 7000
Mary 123456 8000
table2
client accountId soldprice
------------------------
John 1234 9000
Joe 22345 20000
Joe 22345 3000
Mary 0234 8000
Mary 0234 1000
Code:
UPDATE table1
SET price = (SELECT MIN(soldPrice)
FROM table2
WHERE accountId = '22345')
WHERE accountID = '22345'
This should do the trick. A SQL alias is used for the sub-query.