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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:15:45+00:00 2026-05-31T02:15:45+00:00

I have table as P_Id | userid | year | month | day —–+——–+——+——-+——

  • 0

I have table as

P_Id | userid | year | month | day
-----+--------+------+-------+------
 3   |      3 | 2011 |     2 |    2
 5   |      1 | 2011 |     2 |    3
16   |      8 | 2011 |     3 |    4
 5   |      3 | 2011 |     4 |    4
17   |     1  | 2011 |     4 |    6
 8   |      4 | 2011 |     7 |    7
 9   |      3 | 2011 |     8 |    8
10   |      8 | 2011 |     9 |    9

I want to select distinct column i.e userid but also the respective value of year month and year which were encountered first.

For given above table following should be output

P_Id | userid | year | month | day
-----+--------+------+-------+------
   3 |      3 | 2011 |     2 |    2
   5 |      1 | 2011 |     2 |    3
  16 |      8 | 2011 |     3 |    4
   8 |      4 | 2011 |     7 |    7

or
If i am ordering the table by year,month and day
userid which is encountered first must only be selected and rest must be not be selected

  • 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-31T02:15:47+00:00Added an answer on May 31, 2026 at 2:15 am

    Put year, month and day to native date column and do this:

    select p_id, userid, min(the_date) from table group by p_id, userid
    

    It will provide the fastest result.

    If you cant modify your table and should use year+month+day then you can convert this values to date and still use min function.

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

Sidebar

Related Questions

we have a table with 2 million records with PK userid and not unique
Given that I have a table contains user data, like this: userID calltime result
I have a userid table UserId JHOSMI KALVIE etc... What I would like to
I have the following table structure: Inventory: userid - a - b - c
I have a 4 col table, n rows. <table border=0> <tr><td><p>Cell 1 text</p> </td><td>chkbox
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have table inside a div tab. The table has 40 rows in it
Given a table of user points earned, I need to calculate a six month
My database have got 4 table : users id username images id user_id image
I have two tables Users and Expenses in the backend. UserId is a foreignKey

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.