Solved

Make a query to Select data from Two Tables

Posted on 2008-06-24
1
448 Views
Last Modified: 2010-05-18
Board                     Reply
----------------         ---------------------
BoardID (PK)         ReplyID (PK)
Subject                  BoardID (FK)
                              RegisterDate
                              StatusTypeID

Let say I have these two tables. What I need is to collect all the data based on Board Table. The problem is that on Reply Table, there are many reply data with one boardID and I need to seperate the RegisterDate based on StatusTypeID. So if StatusTypeID='12' then it will be AssignDate, and if StatusTypeID='13' then it will be Contaced Date....etc.
Bottom is what the result will be like:

BoardID   Subject   AssignDate              Contacted Date            SignedDate
------------------------------------------------------------------------------------------
1              test          03/01/2008             03/03/2008                    03/05/2008
2              hello        03/01/2008              Null                                Null
3              hi             03/01/2008              03/02/2008                     03/12/2008


Below is what I done so far and the result came out to be wrong:

Select B.BoardID,Subject,RegisterDate, ass.RegisterDate as 'Assigned Date', con.ReigsterDate as 'Contaced Date', sig,RegisterDate as 'Signed Date'
From Board B
Left Join Reply R On R.BoardID=B.BoardID
Left Join Reply ass On StatusTypeID='12'
Left Join Reply con On con.StatusTypeID='13'
Left Join Reply sig On sig.StatusTypeID='14'

Help!
0
Comment
Question by:erin027
1 Comment
 
LVL 32

Accepted Solution

by:
bhess1 earned 500 total points
ID: 21860978
You were close, though.  Try this modification:

Select
      B.BoardID,
      Subject,
      RegisterDate,
      ass.RegisterDate as 'Assigned Date',
      con.ReigsterDate as 'Contacted Date',
      sig,RegisterDate as 'Signed Date'
From Board B
Left Join Reply ass
      On ass.StatusTypeID='12'
      AND ass.BoardID=B.BoardID
Left Join Reply con
      On con.StatusTypeID='13'
      AND con.BoardID=B.BoardID
Left Join Reply sig
      On sig.StatusTypeID='14'
      AND sig.BoardID=B.BoardID
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adventure works database .msi 4 60
sql sERVER PARSE DATA BY HOURS AND COLUMNS 2 42
if and else in stored procedure 19 42
SQL 2005 - Memory Table Column Names 11 68
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

19 Experts available now in Live!

Get 1:1 Help Now