Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top