AdventureWorks Database: Employee name, email separated by a new line

SQL Query - AdventureWorks: Exercise-58 with Solution

58. From the following table write a SQL query to output an employee's name and email address, separated by a new line character.

Sample table: Person.Person

Click to view Full table

Sample table: Person.EmailAddress

Click to view Full table

Sample Solution:

SELECT concat(p.FirstName,' ', p.LastName) || ' '|| chr(10)|| pe.EmailAddress   
FROM Person.Person p 
INNER JOIN Person.EmailAddress pe ON p.BusinessEntityID = pe.BusinessEntityID  
  AND p.BusinessEntityID = 1;

Sample Output:

?column?                             |
Ken Sánchez ¶[email protected]| 

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Product with prefixes of either chain or full.
Next: Find the position of the string 'yellow'.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8