Solved

Grouping the output of a SQL query and displaying it

Posted on 2004-10-12
1
156 Views
Last Modified: 2010-04-01
Hi all,

I have a query with a resultset similar to this:

type | amount
1 | a
1 | b
1 | c
2 | a
2 | b
3 | a

I want the display to look like this:

1 | a
   | b
   | c
2 | a
   | b
3 | a

This is similar to coldfusion and the cfoutput group attribute. Basically, I want anything with duplicates to be removed from the output (given that they are ordered correctly in the query). It is not only this query, it should apply to much larger queries with more columns.

Is there any type of tool to do this or do I have to write something that always checks the previous row's value and then displays whether or not it was the same as the current row?

thank you very much.

Jin
0
Comment
Question by:neojin80
[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
1 Comment
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 125 total points
ID: 12296823
I think you can do this with a loop while creating the table.
Assuming that you have got them in ordered form.
<table>
<%
int myval=-1;
while(rs.next())
{%>
<tr>
<%
if(myval==-1 or myval=rs.getString(1))
{
myval=rs.getint(1)
%>
<td><%=myval%></td>
<%
}else
{%>
<td></td>
<%}
//rest of the processing.
}
%>

This should do the job
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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