Im trying to update a table with data from another table, the relation between the two tables ,
is a one-to-many relation. I have stubbed out a example here:
UPDATE
foo f
INNER JOIN
bar b
ON
b.fooId = f.Id
SET
f.something1 = b.barSome1,
f.something2 = b.barSome1,
f.something3 = b.barSome1,
f.something4 = b.barSome1
But my example only takes me half way,
What I want to do is to select the top 1 bar based on latest
bar.post_date or bar.Id or check if bar.barSome1 (lets say its a varchar) is null or empty.
As it is now it’s some internal ordering of my bar’s
So you’ll need to add a
WHEREclause to limit whichfoorows are modified.To do it by newest
post_dateuse a construct like:Update
To modify all rows of
foowith matching criteria from a single row ofbar, you can use a join against a subquery without anONclause. Test this out first with a SELECT statement. I’ve never tried anything like this and accept no responsibility if it destroys yourfootable. 🙂 Backup first.Test the JOIN
The UPDATE should work the same way