MySQL Forums
Forum List  »  Newbie

Re: conditional return of data in SELECT
Posted by: Phillip Ward
Date: January 26, 2021 04:52AM

Something like this?

select 
  t1.name name
, case 
  when t2.town_name is not null then t2.town_name
  else t1.town 
  end town
from      table1 t1 
left join table2 t2 
     on   t1.town = t2.town_actual 

+------+-----------+
| name | town      |
+------+-----------+
| Ed   | Boston    |
| Mike | Newton    |
| Dave | Malden    |
| Erin | Haverhill |
+------+-----------+

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: conditional return of data in SELECT
January 26, 2021 04:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.