0

I have this existing query

Select 
   mt.First_name,
   mt.Last_name as OLD_Last_name,
   ot.Last_name as New_Last_name,
   ot.Date as Update_Date,
from maintable as mt
JOIN othertable as ot on mt.id=ot.id

I'd like to join a new column with the following output: [mt.First_name] [ot.Last_name], nee [mt.Last_name] changed their name on [ot.Date]. I tried using a case statement but didn't get it right.

2
  • 2
    SELECT mt.First_name || ' ' || ot.Last_name || ', nee ' || mt.last_name || ' changed their name on ' || ot.Date AS yournewcolumn, mt.First_name, mt.Last_name as OLD_Last_name, ot.Last_name as New_Last_name, ot.Date as Update_Date from maintable as mt JOIN othertable as ot on mt.id=ot.id Commented Aug 8, 2022 at 21:00
  • 1
    @JNevill why dodn't you posz this as answer? Commented Aug 8, 2022 at 21:09

1 Answer 1

1

For closure, moving @Jnevill answer from comment to actual answer:

SELECT mt.First_name || ' ' || ot.Last_name || ', nee ' || mt.last_name || ' changed their name on ' || ot.Date AS yournewcolumn, mt.First_name
  ,    mt.Last_name as OLD_Last_name
  ,    ot.Last_name as New_Last_name
  ,    ot.Date as Update_Date 
from maintable as mt 
JOIN othertable as ot on mt.id=ot.id

Apparently OP wanted to know how to concatenate strings, which is done with ||.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.