TSQL: JOIN, for sure it is possible -- but don't know how
TABLE: Services:
ServiceID ServiceName
1 Cleaning
2 Painting
3 Driving
4 Cooking
TABLE: ServiceMembers:
ServiceMemberID Mem开发者_运维百科berID ServiceID
1 10 3
Query:
SELECT s.ServiceName, sm.MemberID
FROM Services s
JOIN ServiceMembers sm ON s.ServiceID = sm.ServiceID
WHERE sm.MemberID = 10
Returns:
Driving 10
Question: How to JOIN tables, so I can get following in TSQL:
Cleaning NULL
Painting NULL
Driving 10
Cooking NULL
Thanks in advance.
This should do it:
SELECT s.ServiceName, sm.MemberID FROM Services s LEFT JOIN ServiceMembers sm ON s.ServiceID = sm.ServiceID AND sm.MemberID = 10
精彩评论