Just need some advice on my query.
I have three tables. Table_1 shows the current status of an order, Table_2 shows historical data on the teams that have worked the order, Table_3 shows the department that the teams are in.
SELECT T1.Key, T1.crrnt_id, T2.From_Team, T3.Teammaster
FROM table_1 T1, table_2 T2, table_3 T3
WHERE Table_3.TeamMaster = 'Main'
AND Table_1.Crnt_Teammaster ='Non-Main'
AND Table_1.Key = Table_2.Key (+)
AND Table_2.From_Team = Table_3.Team_Id (+)
I get two results:
2, 1c, Non-Main, 1a, Main
2, 1c, Non-Main, 1b, Main
If the Where criteria is true, I only want to see one result. On a larger scale this can return dozens of results if an order is currently in a non-main bucket, but has been transferred from Main buckets repeatedly. Is there are way to show only one result per Key if the WHERE condition is true?
Below are some examples on the three tables:
Key crrnt_id Crnt_tmmstr
1 1b Main
2 1c Non-Main
Key from_team to_team
1 1a 1b
2 1a 1c
2 1c 1b
2 1b 1c