Hi everybody, someone can explain me?
mysql> select * from log_funcionario where cod_log in (select max(cod_log) from log_funcionario where cod_funcionario="51" and tipo = 'logado');
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (3 min 30.80 sec)
Now in parts:
mysql> select max(cod_log) from log_funcionario where cod_funcionario="51" and tipo = 'logado';
+--------------+
| max(cod_log) |
+--------------+
| 26432 |
+--------------+
1 row in set (0.01 sec)
mysql> select * from log_funcionario where cod_log in (26432);
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (0.00 sec)
And now another code:
mysql> select * from log_funcionario where cod_funcionario="51" and tipo = 'logado' order by cod_log desc limit 0,1;
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (0.00 sec)
The table's backup:
http://www.4shared.com/document/X11Set51/h_log_f.html