In my MySQL database I have defined a function called isUserVerified that return the status of a user.
I am trying to use the function in a SQL statement:
SELECT id, isUserVerified(id) AS verification FROM users
But I get the following error:
1222 – The used SELECT statements have a different number of columns
This is my function definition:
BEGIN DECLARE isVerified VARCHAR(10); SELECT users.profile_verification, users.id INTO isVerified FROM users WHERE users.id = user_id; RETURN isVerified; END
What am I missing?
Advertisement
Answer
You are selecting two columns but inserting into only one variable. Presumably, you intend:
SELECT users.profile_verification INTO isVerified