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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:28:06+00:00 2026-06-05T16:28:06+00:00

I have a table of format id name flag —————- 11 Jack 1 11

  • 0

I have a table of format

    id name flag
  ----------------
    11 Jack  1
    11 Jill  2
    23 Joe   1
    23 John  2
    23 Sam   1
    46 White 2
    46 Dan   2
    57 Dave  1

I am trying to return the table of format (based on the flag for particular id) like

    id name_1 name_2
   ------------------
    11 Jack   Jill
    23 Joe    John
    23 Sam    John
    46 NULL   White
    46 NULL   Dan
    57 Dave   NULL

I tried this query but it does not give the expected result.

select id,
case flag when 1 then name end as name_1,
case flag when 2 then name end as name_2
from temp;
  • 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-06-05T16:28:10+00:00Added an answer on June 5, 2026 at 4:28 pm

    You want a join, not a select case. Something like this, assuming null is possible in either column:

    SELECT a.id, a.name fname, b.name lname from
    (SELECT id, name FROM temp WHERE flag = 1) a 
    full outer join 
    (SELECT id, name FROM temp WHERE flag = 2) b on a.id = b.id
    

    Not sure what you expect in this case though:

    46 NULL   White
    46 NULL   Dan
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing some joins and stuff I have table in the following format name
I have a table named People in the following format: Date | Name .
I have a table that contains company names in this format: Name Name ,
I have a table in the format Date | Name | Result --------------------------- 2012-05-02
I have a SQLite database with this format: TABLE users | |---------name - text
I have a table with the format ID NAME NICKNAME MENTOR_NAME MENTOR_NICKNAME ------------------------------------------------ 01
I want to get array format from mysql database. Example,Let I have name table
I have a table in this format. <table> <tr> <td id=divOne>div one</td> <td id=divOne>2222</td>
I want to display a ListView in table format. The ListView should have rows
I have a table in sql where the date format is stored in Hijri.

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.