MySQL stored procedure, where the problem with the sentence

I have 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 do not have limit 1 in place, it always returns all the rows in the table - with each record identifier value set to the ID parameter. Why can't I use id id and why does it return all records when I do this? What are the consequences of using limit 1? Why am I programming on Saturday?

+3
source share
2 answers

Because it is a comparison of t.id with itself, which will always be true. Call your official parameter something else.

+7
source

MySQL . id id, where . , , , . .

+2

All Articles