Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display 2 record on a single line

 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetesh,
Why can't you loop through the result set and just output the result on one line?
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic