user5493659
user5493659

Reputation:

Android sqlite fetch anyone row in different groups

I am having a table "example". In that table I am having 3 columns say name,id,dept. Here except dept other two is unique i.e,. records should not be repeated.

name | id |dept

a |1 |electronics

b | 2 |electronics

c | 3 |information technology

d | 4 |information technology

e | 5 |mechanical

f | 6 |mechanical

here i want to return

name | id |dept

a |1 |electronics

c | 3 |information technology

e | 5 |mechanical

i tried with using distinct keyword but it returns nothing.

Thank you in advance

Upvotes: 0

Views: 35

Answers (3)

user5493659
user5493659

Reputation:

I finally found answer to my question my senior helped me out instead of using distinct we have to use group by.Code is SELECT * FROM example GROUP BY dept;

Upvotes: 1

karimkhan
karimkhan

Reputation: 329

you must define an additional column for your table that it has a same value for your required outputs. then you can select all from table that has value in new column. hope you know what i mean.

Upvotes: 0

Hedegare
Hedegare

Reputation: 2047

Use the Distinct keyword to perform that query. For example:

SELECT DISTINCT <column_name> FROM <table_name>;

If it returns nothing, you probably have some errors on your code or database.

Upvotes: 0

Related Questions