How can i get the unique rows from a table in sqlite database android
Asked
Active
Viewed 28 times
1 Answers
0
Suppose, I have 5 rows in a table(user_table) like below
id | name | dcode | tno | dname |
---|---|---|---|---|
1 | satheesh | A01 | 2 | ABC |
2 | mahesh | A01 | 2 | ABC |
3 | suresh | A02 | 1 | ABC |
4 | naresh | A02 | 1 | ABC |
5 | rajesh | A03 | 3 | ABC |
To get unique rows with dcode
@Query("select distinct dCode, tno, dname from user_table")
suspend fun getUniqeList(): List<UserDataModel>?
and create UserDataModel class like below
data class UserDataModel (
var dCode: String? = null,
var tno: String? = null,
var dname: String? = null,
)
it will print only three row like below
dcode | tno | dname |
---|---|---|
A01 | 2 | ABC |
A02 | 1 | ABC |
A03 | 3 | ABC |

Satheesh Guduri
- 353
- 4
- 8