Reputation: 43
I wanted get id of something whose barcode is either empty or barcode state is active. Barcode state is stored in another table. Here is what I tried
SELECT a.id from a
where a.bar=''
OR a.bar=(SELECT b.barcode from b where b.barcode=active)
But it gives me nothing when there are some results should come. Where did I make mistake?
Thanks in advance
Upvotes: 1
Views: 60
Reputation: 24144
I guess your subquery returns more than one record so in this case you have to use IN
instead of =
. Also I guess b.barcode
is a varchar field so you should use a varchar constant 'active'
SELECT a.id from a
where a.bar=''
OR a.bar IN (SELECT b.barcode from b where b.barcode='active')
Upvotes: 0
Reputation: 553
SELECT a.id FROM a
WHERE a.bar=''
OR a.bar IN (SELECT b.barcode FROM b WHERE b.barcode='active')
Upvotes: 1
Reputation: 1054
you can use raw query:
here is the code for it
Cursor getData(String a){
return db.rawQuery(SELECT a.id from a where a.bar='' OR a.bar=(SELECT b.barcode from b where b.barcode=active));
}
Upvotes: 0