I have a table like this
id type type_id cust ip_address datetime
395 Category 5 0 119.63.196.29 2012-11-27 00:34:21
394 Cart 812 0 84.208.217.178 2012-11-27 00:31:48
393 Cart 812 0 84.208.217.178 2012-11-27 00:31:41
392 Cart 812 0 84.208.217.178 2012-11-27 00:31:35
391 Product 812 0 84.208.217.178 2012-11-27 00:31:34
i want to select 4 rows, ordered by id desc, which have distinct type+type_id data.
so the result from the query would remove id 393 and 392, because type and type_id combination is already in id 394.
pseudocode: select * from table where type and type_id is distinct from resultset, order by id desc limit 4
1 Answer