query efficiency - select the 2 latest “group/batch” records from table
问题 We have a tested a quite interesting SQL query. Unfortunately, It turned out that this query runs a little bit slow - O(n2) - and we are looking for a optimized solution or maybe also a totally different one? Goal: We would like to get for: - some customers ("record_customer_id"), e.g. ID 5 - the latest 2 "record_init_proc_id" - for every "record_inventory_id" http://www.sqlfiddle.com/#!9/07e5d/4 The query works fine and shows the correct results but uses at least two full table scans which