Jangan lakukan itu, ini cara yang lebih baik, pertama, tambahkan bidang untuk menyimpan di tabel pengguna ID terakhir dari entri log baru, lalu buat pemicu yang memperbarui bidang itu pada setiap bidang baru yang dimasukkan, lalu ( opsional) buat tampilan untuk memiliki "tabel" lengkap untuk kueri.
-- Add new field to save the modified id
ALTER TABLE `users` ADD `last_mod_id` INT(11) NOT NULL, ADD INDEX (`last_mod_id`);
-- Drop the trigger just in case it exists
DROP TRIGGER IF EXISTS `update_last_id`;
-- Create a trigger to save the last modified id each time a row is created
DELIMITER ;;
CREATE TRIGGER update_last_id
AFTER INSERT ON user_log
FOR EACH ROW
BEGIN
UPDATE `users`
SET `last_mod_id` = NEW.id
WHERE `id` = NEW.idrel;
END;
;;
-- Emtpy your table
TRUNCATE `user_log`;
-- Create all new registries
INSERT INTO `user_log` VALUES (1,1,'log1','2014-01-01 13:00:00');
INSERT INTO `user_log` VALUES (2,1,'log2','2014-01-02 13:00:00');
INSERT INTO `user_log` VALUES (3,2,'log3','2014-01-03 13:00:00');
INSERT INTO `user_log` VALUES (4,2,'log4','2014-01-04 13:00:00');
INSERT INTO `user_log` VALUES (5,3,'log5','2014-01-05 13:00:00');
INSERT INTO `user_log` VALUES (6,3,'log6','2014-01-06 13:00:00');
-- Query
SELECT
u.id,
u.name,
u.last_mod_id,
l.event,
l.log
FROM
`users` as u
INNER JOIN
`user_log` as l
ON (l.id = u.last_mod_id)
-- Drop view if exists
DROP VIEW IF EXISTS `users_log_view`;
-- View
CREATE VIEW `users_log_view` AS
SELECT
u.id,
u.name,
u.last_mod_id,
l.event,
l.log
FROM
`users` as u
INNER JOIN
`user_log` as l
ON (l.id = u.last_mod_id);
-- Query
SELECT * FROM `users_log_view` WHERE `id` = 1;