Hi! I have two table with data.
DROP TABLE #DEPORTMENT
CREATE TABLE #DEPORTMENT(Id INT, NAMEDEP VARCHAR(10))
INSERT INTO #DEPORTMENT(Id, NAMEDEP)
SELECT 1,'DENTIST'
UNION ALL
SELECT 2,'UROLOGY'
UNION ALL
SELECT 3,'EYE DOCTOR'
SELECT * FROM #DEPORTMENT
DROP TABLE #HOSPITAL
CREATE TABLE #HOSPITAL(Id INT, DEPORT INT, NUMBER INT)
INSERT INTO #HOSPITAL(Id, DEPORT, NUMBER)
SELECT 1,1, 1
UNION ALL
SELECT 2,1, 1
UNION ALL
SELECT 3,3, 1
UNION ALL
SELECT 4,2, 1
UNION ALL
SELECT 5,1, 1
UNION ALL
SELECT 6,2, 1
UNION ALL
SELECT 7,3, 1
UNION ALL
SELECT 8,2, 1
UNION ALL
SELECT 9,3, 1
UNION ALL
SELECT 10,2, 1
UNION ALL
SELECT 11,3, 1
UNION ALL
SELECT 12,3, 1
SELECT * FROM #HOSPITAL
I want below result. Output result:
Id
|
DENTIST
|
UROLOGY
|
EYE DOCTOR
|
1
|
3
|
4
|
5
|