Solved

join

Posted on 2011-09-16
8
328 Views
Last Modified: 2012-06-27
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
Comment
Question by:patd1
  • 3
  • 3
8 Comments
 
LVL 15

Expert Comment

by:tim_cs
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

Open in new window

0
 
LVL 15

Accepted Solution

by:
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

Open in new window

0
 
LVL 15

Assisted Solution

by:Haris Djulic
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Expert Comment

by:Haris Djulic
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

Open in new window

0
 
LVL 15

Expert Comment

by:tim_cs
ID: 36551673
Did mine not work?
0
 

Author Comment

by:patd1
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

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now