0

Hi I cant get unique rows tried this from the documentation:

public Cursor getcepaUnico(){
return database.query(true, "vino", new String[] {"_id", "cepa"}, null, null, null, null, "cepa", null);}

but shows duplicated rows even if the DISTINCT boolean is changed. Also tried this:

public Cursor getCepaUnico() {
return database.rawQuery("select DISTINCT cepa from vinos", null);}

And the app crash after calling the method.

2 Answers 2

2

Setting distinct to true should have returned distinct results. Is it possible that your code which loops through the cursor is incorrect? You might want to post that also for review.

Regarding your rawQuery, you are using a different table name which is probably what is causing the crash. It should be "select DISTINCT cepa from vino" (not vinos) to match your query statement.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you! that solved the crash, now it shows duplicated rows as I want id's and cepas it seems to take different id's and not different cepas.
2

Not sure if this will solve your problem, but sometimes I just pull the db from the emulator (in the DDMS view in Eclipse) and run the query directly using an sqlite editor when my raw queries don't work; if the query shows what you want in the editor then use the query in the rawQuery method.

Firefox has a good sqlite editor.

1 Comment

yes it only works when I just want the column cepas as: SELECT DISTINCT cepa from vino, when I try to get the row _id it shows duplicated rows this is the query: SELECT DISTINCT cepa, _id from vino it seems to get only distinct id's not cepas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.