---------------- c_id s_id p_id (customer_id, service_id, provider_id) ---- ---- ------ 1, 1, 1 - not elegible to select as next entry has same p_id 1, 2, 1 1, 3, 3 2, 1, 1 2, 2, 2 2, 3, 3 3, 1, 3 - not elegible to select as next entry has same p_id 3, 2, 3 - not elegible to select as next entry has same p_id 3, 3, 3
What is the cost effective way of writing the query to produce below result from above data ?
---------------- c_id s_id p_id ---- ---- ------ 1, 2, 1 1, 3, 3 2, 1, 1 2, 2, 2 2, 3, 3 3, 3, 3