Saturday, 15 June 2013

mysql: Select from table1 rows that are missing in table2 -



mysql: Select from table1 rows that are missing in table2 -

i've been struggling code while. copied it, , altered so-question, cannot work.

i have table(scores) holds username, userid , score. , table called userlocations, holds userid, city, country, lat , long coordinates.

what need list every row in scores-table doesn't have row in table userlocation identical userid.

select scores.userid , case when userlocations.userid not null 1 else 0 end row_exists scores left outer bring together (select distinct userid userlocations) userlocations on scores.userid = userlocations.userid

if want list of rows inscoresthat don't have matchinguseridinuserlocationsi believe query should give performance:

select * scores s not exists ( select 1 userlocations ul ul.userid = s.userid )

mysql

No comments:

Post a Comment