Solved

# join

Posted on 2011-09-16
323 Views
table PX
CID, projectEndDate, memberid, providerid, POs
1, 2011-06-30 23:59:00, 12345, 09876, IP
2, 2012-06-30 25:59:00, 12345, 09876, IP
3, 2011-06-30 24:59:00, 23456, 98765, OP
4, 2011-06-30 23:59:00, 23456, 98765, OP
5, 2011-06-30 23:59:00, 34567, 87654, IP
6, 2011-06-30 23:59:00, 45678, 76543, OP

Table MasterChild contains CID from table PX as master child associations.
MasterCID, ChildCID
2,1
3,4

How do i join the above two tables to show projectEndDate for both MasterCID and ChildCID as follows:
MasterCID, MasterProjectStartDate, ChildCID, ChildProjectStartDate
2, 2012-06-30 25:59:00, 1, 2011-06-30 23:59:00
3, 2011-06-30 24:59:00, 4, 2011-06-30 23:59:00

Thank you.

0
Question by:patd1
• 3
• 3

LVL 15

Expert Comment

ID: 36551388

``````SELECT
A.MasterCid
B.ProjectEndDate
,A.ChildCID
,C.ProjectEndDate
FROM
MasterChild A
INNER JOIN PX B
ON A.MasterCID = B.CID
INNER JOIN PX C
ON A.ChildCid = C.CID
``````
0

LVL 15

Accepted Solution

tim_cs earned 250 total points
ID: 36551399
Missed a comma.
``````SELECT
A.MasterCid
,B.ProjectEndDate
,A.ChildCID
,C.ProjectEndDate
FROM
MasterChild A
INNER JOIN PX B
ON A.MasterCID = B.CID
INNER JOIN PX C
ON A.ChildCid = C.CID
``````
0

LVL 15

Assisted Solution

Haris Djulic earned 250 total points
ID: 36551469
select f.MasterCID, e.projectEndDate as projectstartdate, f.ChildCID , g.projectEndDate as enddate
from (select cid, projectEndDate from PX) as  e
left join MasterChild  f on e.cid=f.MasterCID
left join (select cid, projectEndDate from PX) as  g on g.cid=f.ChildCID
0

LVL 15

Expert Comment

ID: 36551477
removed the Null joins...

``````select f.MasterCID, e.projectEndDate as projectstartdate, f.ChildCID , g.projectEndDate as enddate
from (select cid, projectEndDate from PX) as  e inner join MasterChild  f on e.cid=f.MasterCID
inner join (select cid, projectEndDate from PX) as  g on g.cid=f.ChildCID
``````
0

LVL 15

Expert Comment

ID: 36551673
Did mine not work?
0

Author Comment

ID: 36551711
oops! I meant to accept multiple solutions, but clicked on the other button by mistake. I tested both and they bot worked. In fact I found your solution to be simpler to understand. I am sorry. I don't know if I can change it to mark both solutions as accepted. Good learning experience. Thanks a ton!
0

LVL 15

Expert Comment

ID: 36558475
Is this question going to be closed?
0

## Featured Post

### Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…