August 30, 2007 at 1:28 am
Consider the following tables
MANAGERID
101
102
103
104
MANAGERID-------EMPID
101 ----------------24
101-----------------25
101 ----------------26
104 --------------- 27
Write sql query to get the following output without using minus,union,intersect.
MANAGERID -------------------------EMPID
101 ---------------------------------- 24
101------------------------------------25
101 -----------------------------------26
102 -----------------------------------N/A
103 -----------------------------------N/A
104 -----------------------------------27
August 30, 2007 at 1:41 am
Is this a homework question?
John
August 30, 2007 at 2:13 am
, use left outer join and isNULL with 'N/A'
August 30, 2007 at 2:43 am
Hey this is not working out
August 30, 2007 at 2:53 am
So please show us what you've tried so far and we'll see how we can help. We're not going to give you the answer on a plate, though.
John
August 30, 2007 at 2:58 am
DECLARE @managerIDs TABLE ( managerID INT )
DECLARE @managerEmps TABLE
( managerID INT
, empID INT
)
INSERT INTO @managerIDs
VALUES ( 101 )
INSERT INTO @managerIDs
VALUES ( 102 )
INSERT INTO @managerIDs
VALUES ( 103 )
INSERT INTO @managerIDs
VALUES ( 104 )
INSERT INTO @managerEmps
VALUES ( 101, 24 )
INSERT INTO @managerEmps
VALUES ( 101, 25 )
INSERT INTO @managerEmps
VALUES ( 101, 26 )
INSERT INTO @managerEmps
VALUES ( 104, 27 )
SELECT m.managerID
, COALESCE(CAST(empID AS CHAR(3)), 'N/A') AS empid
FROM @managerIDs AS m
LEFT JOIN @managerEmps AS me ON m.managerID = me.managerID
Note that I agree with John that we should not be doing the homework of others
Andras
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply