Dongbae Dongbae - 4 months ago 21
MySQL Question

Passing in table for a procedure

How can someone pass in a table into a procedure and then output the first names inside the table?


firstName | lastName

John, Smith
Joe, Smith
Stan, Smith

And then only John, Joe and Stan pops up? I'm trying to make something similar for my personal website.

Here is what I have for MySQL:

CREATE PROCEDURE 'test'.'returnFirstName' ()


Try this:

CREATE PROCEDURE `test`.`returnFirstName` ()
  SELECT firstName 
  FROM myTable

To pass a parameter look at this: use a variable for table name in mysql sproc

Execution SQL:

SELECT test.returnFirstName();