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 7548987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:50:12+00:00 2026-05-30T09:50:12+00:00

I have a table like col1 col2 col3 abc 123 A abc 345 B

  • 0

I have a table like

col1 col2 col3
abc  123  A
abc  345  B
def  567  A
ghi  890  B

I want to have the data in one row related to an element. Col3 is the discriminator element. Only the ‘A’ and ‘B’ rows are related. Result should look like

col1 col2A col2B
abc  123   345
def  567   --
ghi  --    890

How can i do that??

  • 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-30T09:50:13+00:00Added an answer on May 30, 2026 at 9:50 am

    That might not be case to use self join. This will work for the data you posted:

    select 
        col1,
        max(case col3 when 'A' then col2 else null end) col2A,
        max(case col3 when 'B' then col2 else null end) col2B
    from YourTable
    group by col1
    

    Of course, if you have data like below, it would fail:

    col1 col2 col3
    abc  123  A
    abc  345  B
    abc  567  A
    

    Then again, not only the query would fail, but your whole business rule would fail if you have data like this.

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

Sidebar

Related Questions

I have a table which looks like Col1 col2 col3 col4 col5 1 5
I have a table which looks like Col1 col2 col3 col4 col5 1 5
I have a table like this Table1 Col1 Col2 Col3 Col4 Col5 Col6 Col7
I have a table that looks like this: Col1 Col2 Col3 Col4 a b
So I have this temp table that has structure like: col1 col2 col3 col3
I have a table that looks like this: id, col1, col2 col3 0 Goat
I have table like this col1 col2 col3 3 5 8 4 5 5
Situation is as below. I have a table like here: Col1 Col2 Col3 Col4
I have an html table like below +-------+-------+-------+-------+-------+---------+---------+---------+---------+ | col1 | col2 | col3
If i have table something like: col1 col2 col3 col4 apple 1 35 1

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.