I'm trying to create a procedure that inserts the data of a new lecturer, then shows the last 3 lecturers added. This is what my table (lecturers) looks like:
emp_id INT UNIQUE PRIMARY KEY,
first_name VARCHAR(20),
last_name VARCHAR(20),
faculty VARCHAR(3)
And this is my attempt to create the procedure:
DELIMITER //
CREATE PROCEDURE new_lect (IN emp_id INT, first_name VARCHAR(20), last_name VARCHAR(20), faculty VARCHAR(3))
BEGIN
INSERT INTO lecturers (emp_id, first_name, last_name, faculty) VALUES (emp_id, first_name, last_name, faculty);
SELECT * FROM lecturers
ORDER BY emp_id DESC
LIMIT 3;
END//
DELIMITER ;
Then I call the procedure with this data for example:
CALL new_lect(109,'Charlie','Smith','MAT');
However, ORDER BY does not seem to be doing its job because I always receive employee 100, 101, 102 instead of 107, 108, 109.
What am I doing wrong?