Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL stored procedure where clause problem

I've got a mySql stored procedure that looks like this--

delimiter |
create procedure GetEmployeeById(in ID varchar(45))
begin
  select id,
      firstName,
      lastName,
      phone,
      address1,
      address2,
      city,
      state,
      zip,
      username,
      password,
      emptypeid
  from myschema.tblemployees t
  where
      t.id=ID limit 1;
end |
delimiter;

If i don't have the limit 1 in place, it always returns all of the rows in the table--with each record's id value set to the ID parameter. Why can't i just use where id=ID, and why does it return all of the records when i do? What are the implications of me using limit 1? Why am i programming on a saturday night?

like image 317
Micah Avatar asked Dec 14 '22 05:12

Micah


1 Answers

Because, it's comparing t.id with itself, which will always be true. Call your formal parameter something else.

like image 164
MarkR Avatar answered Dec 17 '22 23:12

MarkR