Solved

Displaying data from the same table value but in a different column

Posted on 2014-02-13
4
1,261 Views
Last Modified: 2014-02-17
I am trying to write a report where a particular record can have more than one record associated with it on another table. The problem is I want to see it for that same record in a different column so that we can see it all as a bigger picture. I have tried to use aliases but I do not know how to get the data to appear inside those columns. Below is the main query but I also want to add the information for activity value description with a different activity 'STUD' to go along with 'FINSUP'

select c.label_name, c.status, a.activity_value_desc as Financial_Support_Type, a.activity_value_desc as student_status 
FROM contacts C

INNER JOIN contact_categories cc ON cc.contact_number = c.contact_number 
INNER JOIN activity_values A ON a.activity_value = cc.activity_value 

WHERE cc.activity = 'FINSUP' 

ORDER BY c.label_name

Open in new window

0
Comment
Question by:MSSC_support
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Author Comment

by:MSSC_support
ID: 39856568
As you can see in the image below, I have seperated out the columns I want but I want the last column to display the information for the activity_value 'STUD' rather than the same information in ' FINSUP'

picture of table output
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39856741
Add fields you need into the select-clause from tables aliased with dd and/or b:
SELECT	c.label_name
,	c.status
,	a.activity_value_desc as Financial_Support_Type
,	a.activity_value_desc as student_status 
FROM	contacts		c
JOIN	contact_categories	cc	ON	cc.contact_number = c.contact_number 
					AND	cc.activity = 'FINSUP' 
JOIN	activity_values		a	ON	a.activity_value = cc.activity_value 
JOIN	contact_categories	dd	ON	c.contact_number = dd.contact_number
					AND	cc.activity = 'STUD' 
JOIN	activity_values		b	ON	b.activity_value = dd.activity_value 

ORDER
BY	c.label_name

Open in new window

0
 

Author Comment

by:MSSC_support
ID: 39858450
Hi John,

The above failed to bring back any results. I may see what I can do with it to however.

Thanks,
Jayson
0
 

Author Closing Comment

by:MSSC_support
ID: 39865104
I managed to get it working using the segment of SQL provided.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

717 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