Solved

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

Posted on 2014-02-13
4
1,219 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
  • 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

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.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 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