How can I use a function argument s to stand in for a column name in a query? I'm using mysql 5.5. I tried
SELECT count_distinct(last_name)
but it returns
ERROR 1054 (42S22): Unknown column 'last_name' in 'field list'
The function was defined as
CREATE FUNCTION count_distinct (s CHAR(20) )
RETURNS INT
READS SQL DATA
RETURN( SELECT COUNT(DISTINCT s) FROM president);
I expected it to return a value of 37 as
SELECT COUNT(DISTINCT last_name) FROM president
returns 37. The 'president' table is from the sampdb database from MySQL by Paul Dubois.