mysql - Select columns that do not appear with another column value -
mysql - Select columns that do not appear with another column value -
i have table 2 columns uid , gid there many-to-one gid-uid relationship (i.e. each uid can appear in many rows different gids).
if want uids have gid, that's easy
select uid mytable gid = x but if want uids not have gid? came this:
select uid (select uid, max(gid = x) has_gid mytable grouping uid ) subq has_gid = 0 i think works, seems such hack such simple sounding problem. there obvious or more efficient way i'm missing?
there many ways write such query, i.e. using outer bring together , checking selecting null values, think readable , efficient query utilize not exists sql function
select uid mytable not exists ( select * mytable t1 t1.uid = mytable.uid , t1.gid = x ) mysql
Comments
Post a Comment