I have a query that fetches the list of user IDs and their corresponding user names on a board but from another table also gets a column that has a value (a name) on the row corresponding to the user ID if said user has changed their name. Using an outer join I got the three nicely displayed as in the following example of a few of the results:
member_id name dname_current
1 Blablabla1 blablabla2
2 Bla4444
3 RevZ
5 Herpaderp42
6 Lalalala
7 Kaboom
14 testtesttest21 Formula21
15 Alex Ethan
16 Bob Radio3
The SQL query to get the three columns is as follows:
SELECT
data_members.member_id,
data_members.name,
data_dnames_change.dname_current
FROM data_members LEFT OUTER JOIN data_dnames_change
ON data_members.member_id = data_dnames_change.dname_member_id
GROUP BY data_members.member_id
Is there a way to display this so that it merges the values which exist in the ‘dname_current’ column of that other table into the ‘name’ column, replacing any value that’s already in the corresponding row of that column?
COALESCE()returns the first non-null value, so you can do the following to preferdbname_currentoverdata_members.nameunless it is NULL:Should return: