I am trying to create a view and would like to display the firstName and lastName columns from a table as one column (User) in a view.

The view is using a left join. What I would like to do is join on userID from tableA with concat of firstName and lastName from tableB.

Is this possible in MySql? I have seen some proposed solutions for SQL Server.

Instead of displaying emailAddress column as per below view, I want to display a concat of firstName and lastName columns.

create or replace view document.Documents
    ,cu.emailAddress as createdByUser
from document.Document as d
        left join customer.User as cu
            on cu.userID = d.recCreatedByUserID

Yes, use concat or concat_ws:

  SELECT concat_ws(' ', firstName, lastName) as "User" 
  FROM mytable; 
  • Thanks for the initial answer. I updated the question to reflect a more detailed scenario of what I am trying to achieve. – kravb May 25 '19 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.