sql - Selecting row with latest timestamp MySQL with Duplicates -


i trying select row latest timestamp. here's sample of table:

+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+ | id     | tester_name | frame            | board_name | config | part_no | serial_no | license_count | legal_enabling | last_checked        | log_name                                | +--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+  | 162936 | uflex-10    | test_head th 1 | hsd-m      | 6      | 974-331-44 | 302501d   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162937 | uflex-10    | test_head th 1 | hsd-m      | 7      | 974-331-44 | c0165ec   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162938 | uflex-10    | test_head th 1 | hsd-m      | 8      | 974-331-44 | c13100e   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162939 | uflex-10    | test_head th 1 | hsd-m      | 9      | 974-331-44 | 302c919   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162941 | uflex-10    | test_head th 1 | hsd-m      | 14     | 974-331-44 | c00b41b   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162942 | uflex-10    | test_head th 1 | hsd-m      | 15     | 974-331-44 | c13101e   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162943 | uflex-10    | test_head th 1 | hsd-m      | 16     | 974-331-44 | 3014a1b   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 162944 | uflex-10    | test_head th 1 | hsd-m      | 17     | 974-331-44 | 302cc7e   |               |                | 2015-08-01 19:48:48 | igxleventlog.8.1.2015.19.48.15.054.log  | | 166555 | uflex-10    | test_head th 1 | hsd-m      | 6      | 974-331-44 | 302501d   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166556 | uflex-10    | test_head th 1 | hsd-m      | 7      | 974-331-44 | c0165ec   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166557 | uflex-10    | test_head th 1 | hsd-m      | 8      | 974-331-44 | c13100e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166558 | uflex-10    | test_head th 1 | hsd-m      | 9      | 974-331-44 | 302c919   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166560 | uflex-10    | test_head th 1 | hsd-m      | 14     | 974-331-44 | c00b41b   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166561 | uflex-10    | test_head th 1 | hsd-m      | 15     | 974-331-44 | c13101e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166562 | uflex-10    | test_head th 1 | hsd-m      | 16     | 974-331-44 | 3014a1b   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166563 | uflex-10    | test_head th 1 | hsd-m      | 17     | 974-331-44 | 302cc7e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log |  +--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+ 

the query use above is

select ti.*  new_otpms.tbl_tester_online_info ti  inner join tbl_tester_list tl  on ti.tester_name = tl.tester_name  ti.board_name = 'hsd-m'  , tl.tester_type = 'uflex'  , ti.tester_name = 'uflex-10'  order ti.tester_name; 

as can see gets table. want rows based on latest time stamp only. note: not 1 row latest time stamp, non duplicated row based on config, same latest time stamps.

the latest/the rows want

+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+ | id     | tester_name | frame            | board_name | config | part_no | serial_no | license_count | legal_enabling | last_checked        | log_name                                | +--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+ | 166555 | uflex-10    | test_head th 1 | hsd-m      | 6      | 974-331-44 | 302501d   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166556 | uflex-10    | test_head th 1 | hsd-m      | 7      | 974-331-44 | c0165ec   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166557 | uflex-10    | test_head th 1 | hsd-m      | 8      | 974-331-44 | c13100e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166558 | uflex-10    | test_head th 1 | hsd-m      | 9      | 974-331-44 | 302c919   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166560 | uflex-10    | test_head th 1 | hsd-m      | 14     | 974-331-44 | c00b41b   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166561 | uflex-10    | test_head th 1 | hsd-m      | 15     | 974-331-44 | c13101e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166562 | uflex-10    | test_head th 1 | hsd-m      | 16     | 974-331-44 | 3014a1b   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | | 166563 | uflex-10    | test_head th 1 | hsd-m      | 17     | 974-331-44 | 302cc7e   |               |                | 2015-07-29 02:32:39 | igxleventlog.7.29.2015.02.32.05.475.log | +--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+ 

any on this?

edit: have edited data above corresponds question.

try this

select ti.* new_otpms.tbl_tester_online_info ti inner join tbl_tester_list tl on ti.tester_name = tl.tester_name ti.board_name = 'dc30' , tl.tester_type = 'uflex' , ti.tester_name = 'uflex-10' , ti.last_checked = (     select max(last_checked)      new_otpms.tbl_tester_online_info             board_name = 'dc30'         , tester_name = 'uflex-10'     ) 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -