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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:21:50+00:00 2026-06-12T06:21:50+00:00

I have below table Id Stack —————— 1 a 1 b 2 c 2

  • 0

I have below table

Id          Stack
------------------
1             a
1             b
2             c
2             d

I want to get below table result.

Id          Stack
------------------
1             a
2             c

I use DISTINCT but it doesnot work
how can I do it ?
are there any solution by using group by?

  • 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-12T06:21:51+00:00Added an answer on June 12, 2026 at 6:21 am
    CREATE table sampletb(id int, stack varchar(10));
    
    INSERT into sampletb values(1,'a');
    INSERT into sampletb values(1,'b');
    INSERT into sampletb values(2,'c');
    INSERT into sampletb values(2,'d');
    
    SELECT * FROM sampletb;
    
    id          stack
    ----------- ----------
    1           a
    1           b
    2           c
    2           d
    
    
    SELECT id,
           stack,
           row_number() over (partition by id order by stack) as row_number
    from   sampletb;
    

    This query will give you result like this.

    id          stack      row_number
    ----------- ---------- --------------------
    1           a          1
    1           b          2
    2           c          1
    2           d          2
    

    Now making the above query as subquery and getting the columns having
    row_number=1 will give the desire output you wanted.

    select id,stack from 
           (
           SELECT id,
                  stack,
                  row_number() over (partition by id order by stack) as row_number 
           FROM   sampletb) x
    where  x.row_number=1;
    
    id          stack
    ----------- ----------
    1           a
    2           c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below table. I am trying to get tbody column bgcolors matching
I have a table like below: There are multiple WebSiteIDs. I'd like the output
I have search all over Stack Overflow site but I can find an answer
I have a table like below: Table A ---------- ID Field1 Field2 Field3 1
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr
I have a Generic List object which hold below table as its own value.
I have a mysql database with a table structure like below : Table Name
Below I have table - Company id name value year 1 IBM 10 2011
I have the below column on my table what gets binded on pageload, the
I have an SQL table defined as below: CREATE TABLE [TestComposite] ( ID int,

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.