×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Collapsing results to a single row.

Collapsing results to a single row.

Collapsing results to a single row.

(OP)
Hello,
Question about formatting my query results.

I have a customer table and a customer_phone table linked by customer_id field.

When I select records from customer_phone for a particular customer_id I get as many rows as the customer has phone numbers.

For example

select * from customer_phone where customer_id = 123;

Yeilds

Customer_Id    Phone
123            123-345-4567
123            123-345-9987
123            123-345-2232


What I would like is to be able to collapse that to one result somehow but I do not have a clue.

so something like

Customer_Id  Phone1           Phone2            Phone3
123           123-345-4567    123-345-9987      123-345-2232




Any thoughts would be appreciated.


  

RE: Collapsing results to a single row.

my first thought is, this shouldn't have been posted in the ANSI SQL forum

could you mention which database system you're using, please?

also, why couldn't you do the crosstab layout (as that's what it's called) in your application language?

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: Collapsing results to a single row.

whoa, LISTAGG...  first i've heard of that

nice one

smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close