Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:29:23+00:00 2026-05-30T08:29:23+00:00

The trick with this compared to the other questions (e.g. Oracle convert rows to

  • 0

The trick with this compared to the other questions (e.g. “Oracle convert rows to columns”) is that my column values are arbitrary strings, rather than something I can use with decode. Take this query:

The description table here maps people’s names to descriptions, but each person can have multiple descriptions e.g. “wears a hat” or “is tall”.

Select firstName, lastName, 
(Select description from descriptions --This can return any number of rows (0 or more)
 where description.firstName = people.firstName
 and description.lastName = people.lastName
 and rownum <= 3)
from people
where age >= 25;

I would want an output like this:

FIRSTNAME LASTNAME DESCRIPTION1 DESCRIPTION2 DESCRIPTION3
Jeremy    Smith    Tall         Confused        (null)
Anne      Smith    (Null)       (Null)          (Null)
Mark      Davis    Short        Smart           Strong

In the case of less than 3 descriptions, I want nulls there. In the case of more than 3 descriptions, I want to just leave them out.

I am using Oracle 11.1. Can this be done efficiently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:29:24+00:00Added an answer on May 30, 2026 at 8:29 am

    Assuming that you don’t care what order the descriptions are returned in (i.e. Jeremy Smith could just as correctly have a Description1 or “Confused” and a Description2 of “Tall”), you just need to pivot on the row number. If you care about the order the descriptions are returned in, you can add an ORDER BY clause to the window function in the ROW_NUMBER analytic function

    SELECT firstName, 
           lastName,
           MAX( CASE WHEN rn = 1 THEN description ELSE NULL END ) description1,
           MAX( CASE WHEN rn = 2 THEN description ELSE NULL END ) description2,
           MAX( CASE WHEN rn = 3 THEN description ELSE NULL END ) description3
      FROM (SELECT firstName,
                   lastName,
                   description,
                   row_number() over (partition by lastName, firstName) rn
              FROM descriptions
                   JOIN people USING (firstName, lastName)
             WHERE age >= 25)
       GROUP BY firstname, lastname
    

    As an aside, I’m hoping that you’re actually storing a birth date and computing the person’s age rather than storing the age and assuming that people are updating their age every year.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would anyone happen to know a trick that will keep this MSBuild task from
A long time ago I saw this trick in Ruby. Instead of doing (for
Is there any real sequence of characters that always compares greater than any other
I'm trying to inject some CSS that accompanies some other HTML into a C#
I have a LINQ Distinct() statement that uses my own custom comparer, like this:
this is a pretty rough area (fuzzy logic image comparison) that is way above
I've been trying to track this one for literally a month now without any
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
i find this question tricky but what files store method signature info for xml
I'd like to do something like this to tick a checkbox using jQuery :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.