mysql> SELECT fa.actor_id, fc.category_id, -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> GROUP BY fa.actor_id, fc.category_id -> WHERE fa.actor_id < 3; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE fa.actor_id < 3' at line 6 mysql> SELECT fa.actor_id, fc.category_id, -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> WHERE fa.actor_id < 3 -> GROUP BY fa.actor_id, fc.category_id; +----------+-------------+------------+ | actor_id | category_id | film_count | +----------+-------------+------------+ | 1 | 6 | 1 | | 1 | 2 | 1 | | 1 | 13 | 2 | | 1 | 10 | 2 | | 1 | 14 | 1 | | 1 | 4 | 2 | | 1 | 11 | 3 | | 1 | 15 | 1 | | 1 | 8 | 2 | | 1 | 3 | 1 | | 1 | 9 | 1 | | 1 | 5 | 1 | | 1 | 12 | 1 | | 2 | 6 | 1 | | 2 | 8 | 4 | | 2 | 9 | 2 | | 2 | 1 | 1 | | 2 | 14 | 2 | | 2 | 13 | 4 | | 2 | 4 | 2 | | 2 | 2 | 1 | | 2 | 3 | 1 | | 2 | 16 | 2 | | 2 | 12 | 1 | | 2 | 5 | 2 | | 2 | 10 | 1 | | 2 | 7 | 1 | +----------+-------------+------------+ 27 rows in set (0.02 sec) mysql> DROP VIEW s19v1; ERROR 1051 (42S02): Unknown table 'sakila.s19v1' mysql> mysql> CREATE DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW s19v1 -> AS -> SELECT fa.actor_id, fc.category_id, -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> GROUP BY fa.actor_id, fc.category_id; Query OK, 0 rows affected (0.06 sec) mysql> SELECT s.* -> FROM s19v1 AS s -> WHERE s.category_id = 13 -> LIMIT 10; +----------+-------------+------------+ | actor_id | category_id | film_count | +----------+-------------+------------+ | 77 | 13 | 3 | | 95 | 13 | 2 | | 122 | 13 | 1 | | 124 | 13 | 2 | | 1 | 13 | 2 | | 4 | 13 | 3 | | 7 | 13 | 4 | | 47 | 13 | 2 | | 91 | 13 | 1 | | 136 | 13 | 5 | +----------+-------------+------------+ 10 rows in set (0.03 sec) mysql> SELECT s.* -> FROM s19v1 AS s -> WHERE s.category_id = 13 -> AND s.film_count > 4; +----------+-------------+------------+ | actor_id | category_id | film_count | +----------+-------------+------------+ | 136 | 13 | 5 | | 53 | 13 | 5 | | 105 | 13 | 7 | +----------+-------------+------------+ 3 rows in set (0.02 sec) mysql> mysql> SELECT s.* -> FROM -> (SELECT fa.actor_id, fc.category_id, -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> GROUP BY fa.actor_id, fc.category_id) AS s -- subquery -> WHERE s.category_id = 13 -> AND s.film_count > 4; +----------+-------------+------------+ | actor_id | category_id | film_count | +----------+-------------+------------+ | 136 | 13 | 5 | | 53 | 13 | 5 | | 105 | 13 | 7 | +----------+-------------+------------+ 3 rows in set (0.03 sec) mysql> SELECT fa.actor_id, 13 AS fc.category_id, -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> WHERE fc.category_id = 13 -> GROUP BY fa.actor_id -> HAVING film_count > 4; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.category_id, COUNT(fa.film_id) AS film_count FROM film_actor AS fa INN' at line 1 mysql> SELECT fa.actor_id, 13 AS "fc.category_id", -> COUNT(fa.film_id) AS film_count -> FROM film_actor AS fa INNER JOIN film_category AS fc -> ON (fa.film_id = fc.film_id) -> WHERE fc.category_id = 13 -> GROUP BY fa.actor_id -> HAVING film_count > 4; +----------+----------------+------------+ | actor_id | fc.category_id | film_count | +----------+----------------+------------+ | 136 | 13 | 5 | | 53 | 13 | 5 | | 105 | 13 | 7 | +----------+----------------+------------+ 3 rows in set (0.00 sec) mysql> DROP PROCEDURE AllSuppliers; ERROR 1305 (42000): PROCEDURE sakila.AllSuppliers does not exist mysql> mysql> -- A very simple stored procedure mysql> DELIMITER $$ mysql> mysql> CREATE PROCEDURE AllSuppliers() -> BEGIN -> SELECT * FROM Supplier; -> END $$ Query OK, 0 rows affected (0.07 sec) mysql> mysql> DELIMITER ; mysql> CALL AllSuppliers; ERROR 1146 (42S02): Table 'sakila.supplier' doesn't exist mysql> DROP PROCEDURE AllSuppliers; Query OK, 0 rows affected (0.14 sec) mysql> use supply; Database changed mysql> DROP PROCEDURE AllSuppliers; ERROR 1305 (42000): PROCEDURE supply.AllSuppliers does not exist mysql> mysql> -- A very simple stored procedure mysql> DELIMITER $$ mysql> mysql> CREATE PROCEDURE AllSuppliers() -> BEGIN -> SELECT * FROM Supplier; -> END $$ Query OK, 0 rows affected (0.06 sec) mysql> mysql> DELIMITER ; mysql> mysql> -- Call mysql> CALL AllSuppliers; +------+-------+---------+--------+ | SNUM | SNAME | SCITY | STATUS | +------+-------+---------+--------+ | S1 | ABC | Dallas | 10 | | S2 | DEF | Houston | 20 | | S3 | Go go | Houston | 12 | | S4 | P&G | Dallas | 2 | | S5 | Yap | Phoenix | 5 | | S6 | Yue | Dallas | 1 | +------+-------+---------+--------+ 6 rows in set (0.00 sec) Query OK, 0 rows affected (0.23 sec) mysql> DROP PROCEDURE AllSuppliers; Query OK, 0 rows affected (0.08 sec) mysql> mysql> -- A very simple stored procedure mysql> DELIMITER $$ mysql> mysql> CREATE PROCEDURE AllSuppliers() -> BEGIN -> SELECT * FROM Supplier; -> END $$ Query OK, 0 rows affected (0.02 sec) mysql> CALL AllSuppliers; -> $$ +------+-------+---------+--------+ | SNUM | SNAME | SCITY | STATUS | +------+-------+---------+--------+ | S1 | ABC | Dallas | 10 | | S2 | DEF | Houston | 20 | | S3 | Go go | Houston | 12 | | S4 | P&G | Dallas | 2 | | S5 | Yap | Phoenix | 5 | | S6 | Yue | Dallas | 1 | +------+-------+---------+--------+ 6 rows in set (0.00 sec) Query OK, 0 rows affected (0.19 sec) mysql> DELIMITER ; mysql> CALL AllSuppliers; +------+-------+---------+--------+ | SNUM | SNAME | SCITY | STATUS | +------+-------+---------+--------+ | S1 | ABC | Dallas | 10 | | S2 | DEF | Houston | 20 | | S3 | Go go | Houston | 12 | | S4 | P&G | Dallas | 2 | | S5 | Yap | Phoenix | 5 | | S6 | Yue | Dallas | 1 | +------+-------+---------+--------+ 6 rows in set (0.00 sec) Query OK, 0 rows affected (0.15 sec) mysql> mysql> DROP FUNCTION GetAllSuppliers; ERROR 1305 (42000): FUNCTION supply.GetAllSuppliers does not exist mysql> mysql> -- A very simple stored function mysql> DELIMITER // mysql> mysql> CREATE FUNCTION GetAllSuppliers() RETURNS INT -> BEGIN -> DECLARE count INT DEFAULT 0; -> SET count = 0; -- Not really needed. -> -> SELECT COUNT(*) INTO count FROM Supplier; -> -> -- The following is not allowed as result set in function. -> -- SELECT * FROM Supplier; -> -> RETURN count; -> END // ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) mysql> mysql> DELIMITER ; mysql> mysql> -- Call mysql> SELECT GetAllSuppliers(); ERROR 1305 (42000): FUNCTION supply.GetAllSuppliers does not exist mysql> mysql> mysql> DROP FUNCTION GetAllSuppliers; ERROR 1305 (42000): FUNCTION supply.GetAllSuppliers does not exist mysql> mysql> -- A very simple stored function mysql> DELIMITER // mysql> mysql> CREATE FUNCTION GetAllSuppliers() RETURNS INT DETERMINISTIC -> BEGIN -> DECLARE count INT DEFAULT 0; -> SET count = 0; -- Not really needed. -> -> SELECT COUNT(*) INTO count FROM Supplier; -> -> -- The following is not allowed as result set in function. -> -- SELECT * FROM Supplier; -> -> RETURN count; -> END // Query OK, 0 rows affected (0.09 sec) mysql> mysql> DELIMITER ; mysql> mysql> -- Call mysql> SELECT GetAllSuppliers(); +-------------------+ | GetAllSuppliers() | +-------------------+ | 6 | +-------------------+ 1 row in set (0.00 sec) mysql> mysql> DROP FUNCTION GetAllSuppliers; Query OK, 0 rows affected (0.06 sec) mysql> mysql> -- A very simple stored function mysql> DELIMITER // mysql> mysql> CREATE FUNCTION GetAllSuppliers() RETURNS INT DETERMINISTIC -> BEGIN -> DECLARE count INT DEFAULT 0; -> SET count = 0; -- Not really needed. -> -> SELECT COUNT(*) INTO count FROM Supplier; -> -> -- The following is not allowed as result set in function. -> SELECT * FROM Supplier; -> -> RETURN count; -> END // ERROR 1415 (0A000): Not allowed to return a result set from a function mysql> mysql> DELIMITER ; mysql> use sakila; Database changed mysql> SELECT DISTINCT SUM(s.film_count) -> FROM s19v1 AS s -> WHERE s.actor_id = 1; -- test case. +-------------------+ | SUM(s.film_count) | +-------------------+ | 19 | +-------------------+ 1 row in set (0.03 sec) mysql> DROP FUNCTION s19f1; ERROR 1305 (42000): FUNCTION sakila.s19f1 does not exist mysql> mysql> DELIMITER // mysql> mysql> CREATE FUNCTION s19f1 (actorId INT) RETURNS INT DETERMINISTIC -> BEGIN -> DECLARE result INT DEFAULT 0; -> -> SELECT DISTINCT SUM(s.film_count) INTO result -> FROM s19v1 AS s -> WHERE s.actor_id = actorId; -> -> RETURN result; -> END // Query OK, 0 rows affected (0.12 sec) mysql> mysql> DELIMITER ; mysql> SELECT s19f1(1); +----------+ | s19f1(1) | +----------+ | 19 | +----------+ 1 row in set (0.01 sec) mysql> SELECT s19f1(2); +----------+ | s19f1(2) | +----------+ | 25 | +----------+ 1 row in set (0.02 sec) mysql> notee