Whizz
Whizz

Reputation: 5

Subquery returns more than 1 row (Sql Functions)

I have this function that I want to run ... this function needs to return the job_ids that start with A only... I'm confused!

I'm getting this error! any ideas... What I know that a function needs to have parameters, but I don't know what to pass... 23:47:05 select job_id() LIMIT 0, 1000 Error Code: 1242 Subquery returns more than 1 row

delimiter $
create function Job_id()
returns char
reads sql data
begin
    return (select job_id
            from job_history
            where job_id like 'A%');
end$
delimiter ;

Upvotes: 0

Views: 384

Answers (1)

Pep Lainez
Pep Lainez

Reputation: 949

The MySQL documentation for functions says:

Statements that return a result set can be used within a stored procedure but not within a stored function

If you need a result set then, as told by @Michael Berkowsky, use stored procedures or maybe a view will do the trick for your needs.

Upvotes: 1

Related Questions