union - Simplify table with repeated entries MYSQL -


i have created table union of 2 select statements, friends_and_neighbors, , want remove repetitions of two, except not coincide in fields.

simplifying case, have table called friends (that has pairs of users, , link id) , table user includes zip_code, neighbors section. i'm fixing reference user user_id = @usr, , zip_code = @zip. following.

create table friends_and_neighbors (select      user_id   frnd_id,    # choose neighbors zipcode.      zip_code  frnd_zip,   #      0         frnd_link   # reference friendship comes later. user zip_code = @zip) union (select     frd.friend_id frnd_id,      usr.zip_code  frnd_zip,      frd.link      frnd_link friends frd join user usr   on frd.friend_id = usr.user_id frd.user_id = @usr); 

then may counting neighbor/friends twice, still differ in frnd_link column, gave 0 because couldn't join two.
want remove corresponding neighbor row has 0, when has been counted friend.

thank help.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -