android - MySQL relation and entities -
i have 2 tables: place
, discount
n<->n relation. have table called place_discount
has 2 foreign keys (idplace
, iddiscount
).
when add discount place, e.g. discount bar, add in place_discount table.
so issue is: have android app queries on database. when want list places have loaded, want show star on have discount. list select * place
. there way query?
tip: can not use triggers because not have super privileges.
why not use join?
select place.*, if(ifnull(min(place_discount.iddiscount),0)>0,1,0) hasdiscount place left join place_discount on place.id=place_discount.idplace group place.id
will give 1 in hasdiscount
if discount available, 0 if not.
on side note: not need super privilege trigger on table own.
Comments
Post a Comment