Is it possible to do a query like the following? I would like to do this in place of a stored procedure if possible.
for example, with two tables
UPDATE items
SET score='a', count=(SELECT COUNT(votes.id) AS C WHERE votes.uri = items.uri)
WHERE items.id = 'b'
Or something like that… Essentially doing a count on a table and using that value to update another table?
I don’t even know if this question makes sense. Feel free to call me a moron if need be.
Edit sorry, this question might not make sense. I want to count table “B” and use that value to update table “A” in the same query.
Sure, you’ve got the syntax basically right:
This is called a correlated subquery. It’s correlated because you refer to the table in the outer query in the subquery.