sqlite - Android: Knowing when all items in a database have their field set to the same value? -
i have app lets user select every item in list , set "favorite". thought neat if, when items set favorite, button switched "unselect all".
the way i'm thinking doing registering contentobserver, whenever change made checked if items set favorite. realized may not efficient. can't think of other way, though, hints?
how can know items in database have 1 of fields set same value (field favorite = 1, in case)?
here solution should (i believe) "abort fast" if difference found.
it avoids sorting/distinct phase select distinct or group by. approach may slower in situations and/or negligibly faster in others. sqlite darn fast! remember indexes play role in rdmbs performance.
the inner select replaced literal value reduce complexity. in case, amusement.
select exists (select * t val != (select val t limit 1))
Comments
Post a Comment