Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Combine Columns in SQL? This is the homework question: \"Create a query to displ

ID: 3662289 • Letter: C

Question

Combine Columns in SQL?

This is the homework question:
"Create a query to display the full name (lastname, firstname), job, hiredate and employee number for each employee, with the employee number appearing first. Name the column heads Emp#, Employee, Job Title, and Date Hired, respectively."

This is the code I have:
SELECT Employee_ID AS Emp#, Last_Name || First_Name AS Employee, Job_ID AS "Job Title", Hire_Date AS "Date Hired"
FROM employees;

This code runs and it combines the First and Last name into one column but I don't know how to add a comma between Last_Name and First_Name to read Last, First Name. Any help would be amazing! I can't use concat because we haven't learned that. We are on the basics of SQL now.

Explanation / Answer

You can write the query as:

SELECT Employee_ID AS Emp#, (Last_Name||"," || First_Name) AS Employee, Job_ID AS "Job Title", Hire_Date AS "Date Hired"
FROM employees;

The way you are using || to concat last name and first name, you can also put a comma in between putting || as shown above.