models: code name idcompany 001 BLUE 10 002 RED 20 003 BLACK 10 004 WHITE 99 data: date hour model temperature energy 01/01/15 17:55 001 4.5 1 01/01/15 18:00 002 5.5 1 01/01/15 18:05 003 6.3 1 01/01/15 19:01 001 6.5 1 01/01/15 19:05 004 5.5 1 01/01/15 19:10 001 4.5 1 01/01/15 19:15 001 4.5 1 01/01/15 19:20 002 5.5 1 01/01/15 19:25 003 6.3 1 01/01/15 19:30 001 6.5 1 01/01/15 19:35 004 5.5 1 01/01/15 19:40 001 4.5 1 this is what I need: results: filtered by idcompany=10 code name date hour temp energy 001 BLUE 01/01/15 19:40 4.5 1 003 BLACK 01/01/15 19:25 6.3 1I need to bring the last record in data for the idcompany=10. I need this without using cursor or temporary table, would be possible with just one query?