i want to perform a FULL OUTER JOIN
, merging common rows, on three tables.
SELECT * FROM Users
id Username Fullname
== ======== =====================
7 iboyd Ian Boyd
8 nicholle Michelle Karnac
10 jamie Jimmy Chew
3 row(s) affected
SELECT * FROM GrobUsers
id Username Fullname
== ======== =====================
7 iboyd Ian Steven Boyd
8 nicholle Michelle Baker
9 chris Kris Kallme
3 row(s) affected
SELECT * FROM FrobUsers
id Username Fullname
== ======== =====================
7 ian Ian
9 chris Kris K.
10 jamie Jimmy Chew
3 row(s) affected
i want to merge the tables based on the id
column.
This brings up the issue of how do i want conflicts resolved when the other column values differ. The algorithm that may be applied to resolve conflicts between Usernames and FullName is:
if (id's are equal) then pick one; i don't care
i've tried something along the lines of:
SELECT
COALESCE(Users.id, GrobUsers.id, FrobUsers.id) AS id,
COALESCE(Users.Username, GrobUsers.Username, FrobUsers.Username) AS Username,
COALESCE(Users.FullName, GrobUsers.FullName, FrobUsers.FullName) AS Fullname
FROM Users
FULL OUTER JOIN GrobUsers ON GrobUsers.id = Users.id
FULL OUTER JOIN FrobUsers ON FrobUsers.id = .....something......