• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display 2 record on a single line

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seetesh,
Why can't you loop through the result set and just output the result on one line?
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic