I have a table as below :
col1 col2 col3 col4 --------------------------------------- B1 01 ABC 001 B1 02 ABC 001 B1 03 ABC 001 B1 04 ABC 002 B1 05 ABC 002 B1 06 ABC 003 B1 07 ABC 003 B1 08 ABC 004 B1 09 ABC 004 B1 01 DEF 001 B1 02 DEF 001 B1 03 DEF 002 B1 04 DEF 002 B1 05 DEF 002 B1 06 DEF 003 B1 07 DEF 004 B1 08 DEF 004 B1 09 DEF 004
What I would like to have is a filtered table. for every distinct col3 value, it should have distinct elements from col4 and those elements must be chosen by col2 should be the minimum value of the col2. Let me express what I want to have:
col1 col2 col3 col4 --------------------------------------- B1 01 ABC 001 B1 04 ABC 002 B1 06 ABC 003 B1 08 ABC 004 B1 01 DEF 001 B1 03 DEF 002 B1 06 DEF 003 B1 07 DEF 004
Is there any way to implement this in SQL? By the way, I am using SQLite. I do not want to write a Java code to iterate every row of the query results.