How to store a SELECT value in a variable in MYSQL?

0

It's quite simple but I can not find the information I want, people!

I once saw how to do this but it was very shallow, but I'll explain what I want:

I have a variable and I want it to receive the value of a certain column that will come with a select ...

set @CPF = blablabla;
select * from userdocuments where Description = @CPF;
set @userID = Aqui eu quero armazenar o valor da coluna User_id que virá com o select acima;

How do I make this variable @userID receive the value of the column?

    
asked by anonymous 24.01.2018 / 18:10

2 answers

1

Na :

select @userID := User_id from userdocuments where Description = @CPF;

or

select User_id into @userID from userdocuments where Description = @CPF;
    
24.01.2018 / 18:18
0

So

set @userID = (select User_id from userdocuments where Description = @CPF)
    
24.01.2018 / 18:15