aspose file tools*
The moose likes JDBC and the fly likes Display 2 record on a single line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Display 2 record on a single line" Watch "Display 2 record on a single line" New topic
Author

Display 2 record on a single line

Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi all,

Table1
------
Column : empname
values : sammy
smith

What will be my query to display "sammy smith" on the same line? I dont want to iterate through the resultset. In short the Resultset should fetch only one row instead of 2 rows.

Rgds,

Seetesh
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hello all,

If there are 100 records in the table then what would the query be?

Table1
======

Empname
-------
Alan
Joy
Samantha
Nicole
Manish
Asit
....
...

All the empname's has to be displayed in a single line using a select query so that no iteration ie resultset.next() is used in the code.

Rgds,

Seetesh
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

Seetesh,
Why can't you loop through the result set and just output the result on one line?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
and why are two values belonging together in different rows ?

your table should look like:

FIRSTNAME | LASTNAME
--------------------
foo bar
aaaaa bbbbbb

then your query is "SELECT * FROM <YOUR TABLENAME HERE>
and you cna just iterate trough the resultset like



pascal
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Dear Jeanne/Pascal,

I am looking for a "SQL query" which fetches me the concat portion of the records so as to bypass the ResultSet option.

Rgds,

Seetesh
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

Seetesh,
I understand what you are looking for. However SQL doesn't do that, so we are providing you with alternate solutions.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Seetesh,
I understand that you want to convert rows into columns. In other words, you want to display 100 rows of a single column as a single row with 100 columns. If this is correct, then you require (what is known as) a "pivot" query. If you are using an oracle database (forgive me, I couldn't find that information in your post), then a search of the Ask Tom Web site -- for the term "pivot" (and possibly also "query") -- should provide you with a solution to your problem.

By the way, it looks like you've been working on this particular issue for the last five months. Does this mean that you guys have a very relaxed, unpressured work environment? (I'm assuing that you're a currently employed software engineer, and that this problem is related to your work.) If it's that laid back, maybe you've got a job for me in your organization?

Good Luck,
Avi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display 2 record on a single line