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

  • Home
  • SEARCH
  • 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 3303510
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:57:53+00:00 2026-05-17T20:57:53+00:00

I have a table id|level|name level can be 1,2 or 3 what I want

  • 0

I have a table

id|level|name

level can be 1,2 or 3

what I want to get is:

id|lvl1name|lvl2name|lvl3name

I’m using the following query

SELECT L1."name" as lvl1name, L2."name" as lvl2name, L3."name" as
lvl3name, L1.id
 FROM table as L1
       JOIN table as L2 ON L1.id = L2.id
       JOIN table as L3 ON L2.id = L3.id
       WHERE L1.lvl='1' and L2.lvl='2' and L3.lvl='3';

but it is soooooo slow!

there must be a better way to do this. please help

for this example I’m using postgres, but I’d be happy to learn some way that is not database feature dependant.

I can’t write procedures (read only access), and I select this from a view.

  • 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-17T20:57:53+00:00Added an answer on May 17, 2026 at 8:57 pm

    Use:

      SELECT t.id,
             MAX(CASE WHEN t.level = 1 THEN t.name END) AS level1name,
             MAX(CASE WHEN t.level = 2 THEN t.name END) AS level2name,
             MAX(CASE WHEN t.level = 3 THEN t.name END) AS level3name
        FROM YOUR_TABLE t
    GROUP BY t.id
    

    If you need this to be dynamic, you need to use dynamic SQL.

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

Sidebar

Related Questions

I want a table which can only have one record. My current solution is:
If all tables I want to delete from have the column gamer_id can i
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have a table story_category in my database with corrupt entries. The next query
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
I hope somebody can help me here, I have a table that has the
i have the following table structure table location has - id - parentLocation_id (relation
I have a table like this: Item { int ItemID int ParentID string Name
I have a SQL table: CREATE TABLE [UserTable] ( [ID] [int] NULL, [Name] [nvarchar](50)

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.