これが1つの方法です...
CREATE TABLE addresses
(Name VARCHAR(20) NOT NULL
,Address VARCHAR(20) NOT NULL
,is_primary TINYINT NULL
,PRIMARY KEY (name,address)
);
INSERT INTO addresses VALUES
('John Smith','123 Main Str',1),
('John Smith','456 June Str',NULL),
('Mike Dore','893 West St',NULL),
('Jake John','999 East St',NULL),
('Jake John','145 South St',NULL);
SELECT * FROM addresses;
+------------+--------------+------------+
| Name | Address | is_primary |
+------------+--------------+------------+
| Jake John | 145 South St | NULL |
| Jake John | 999 East St | NULL |
| John Smith | 123 Main Str | 1 |
| John Smith | 456 June Str | NULL |
| Mike Dore | 893 West St | NULL |
+------------+--------------+------------+
SELECT DISTINCT x.name
, COALESCE(y.address,x.address) address
FROM addresses x
LEFT
JOIN addresses y
ON y.name = x.name
AND y.is_primary = 1;
+------------+--------------+
| name | address |
+------------+--------------+
| Jake John | 145 South St |
| Jake John | 999 East St |
| John Smith | 123 Main Str |
| Mike Dore | 893 West St |
+------------+--------------+