SQL Interview Questions and answers Part 4 | How to get comma separated values in SQL
Problem Statement:-
Emp_Details Table has four columns EmpID, Gender, EmailID and DeptID. User has to write a SQL query to derive another column called Email_List to display all Emailid concatenated with semicolon associated with a each DEPT_ID as shown below in output Table.
-------------------------------------------------------------------------
𝗝𝗼𝗶𝗻 𝗺𝗲 𝗼𝗻 𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:🔥
-------------------------------------------------------------------------
*Instagram :
/ itjunction4all
*Twitter:
/ sunilkr5672
-------------------------------------------------------------------------
Table and Insert SQL Script :
-------------------------------------------------------------------------
CREATE TABLE Emp_Details (
EMPID int,
Gender varchar,
EmailID varchar(30),
DeptID int)
INSERT INTO Emp_Details VALUES (1001,'M','[email protected]',104)
INSERT INTO Emp_Details VALUES (1002,'M','[email protected]',103)
INSERT INTO Emp_Details VALUES (1003,'F','[email protected]',102)
INSERT INTO Emp_Details VALUES (1004,'F','[email protected]',104)
INSERT INTO Emp_Details VALUES (1005,'M','[email protected]',101)
INSERT INTO Emp_Details VALUES (1006,'M','[email protected]',100)
INSERT INTO Emp_Details VALUES (1007,'F','[email protected]',102)
INSERT INTO Emp_Details VALUES (1008,'M','[email protected]',102)
INSERT INTO Emp_Details VALUES (1009,'F','[email protected]',100)
----------------------------------------------------------------------------------------------------------------------
#SQLInterviewQuestionsandanswers #sqlInterviewQuestions #sqlInterviewQuestionsForTesting #sql InterviewQuestionsQuery #sqlInterviewQuestionsOnJoins #ITJunction4All #ETLQuestion