mysql-error-1146

In MySQL: How to pass a table name as stored procedure and/or function argument?

For instance, this does not work: DELIMITER // CREATE PROCEDURE countRows(tbl_name VARCHAR(40)) BEGIN SELECT COUNT(*) as ct FROM tbl_name; END // DELIMITER ; CALL countRows('my_table_name'); Produces: ERROR 1146 (42S02): Table 'test.tbl_name' doesn't exist However, this works as expected: SELECT COUNT(*) as ct FROM my_tab...

MySQL: Query to obtain recipes using all given ingredients.

hi I have the following simplified tables: CREATE TABLE recipe(id int, name varchar(25)); CREATE TABLE ingredient(name varchar(25)); CREATE TABLE uses_ingredient(recipe_id int, name varchar(25)); I want to make a query that returns all id's of recipes that contain both Chicken and Cream. I have tried SELECT recipe_id FROM uses_...