MySQL Forums
Forum List  »  Newbie

Re: Update column2 on all lines automatically to Y, when column1 is unique and column2 is N
Posted by: Peter Brawley
Date: June 21, 2018 10:46AM

Break problems into parts. The values of col that occur just once in table t are ...

select col, count(*) as X
from t
group by col
having X=1;

... in your case ...

select enti_users, count(*) as X
from tabela_users
group by enti_users
having X=1;

So you can write something like ...

update tabela_users as a
join (
select enti_users, count(*) as X
from tabela_users
group by enti_users
having X=1
) as b using(enti_users)
set a.flgd_users = 'Y'
where a.column2='N';

... substituting the correct name for `column2`.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.