SQL update that seems to require GROUP BY
I have an update I'd like to make to a table, something like
UPDATE mytable
LEFT JOIN worker ON first=worker_first_name && last=worker_last_name
GROUP BY CONCAT(first, '%%', last)
SET taint = COUNT(pkey) > 1;
But of course the table_reference in UPDATE does not allow GROUP BYs. How can I set th开发者_如何学Cis column? It's just checking if the first/last name combination occurs at most once in the other table.
UPDATE mytable
INNER JOIN (
select first, last, COUNT(pkey) > 1 Result
FROM mytable
LEFT JOIN worker ON first=worker_first_name AND last=worker_last_name
GROUP BY first, last) OTHER
on OTHER.first = mytable.first
and OTHER.last = mytable.last
SET taint = OTHER.Result;
Something like:
UPDATE mytable
SET taint = ((select count(pkey) from worker where worker_first_name = first and worker_last_name = last) > 1)
But I'm guessing performance might leave something to be desired. There might be a more performant way.
精彩评论