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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:40:12+00:00 2026-06-12T15:40:12+00:00

i ve a little problem in sql, i can’t reach a way to build

  • 0

i ve a little problem in sql, i can’t reach a way to build the correct statement. i need to include in the result only the row having the maximum “sess” when “etud” and “mod” are equal in the occurrences :

etud|sess|mod|eta
1------1---M1--nv
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v

now the result i need is :

etud|sess|mod|eta
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v

Thanks in advance .

  • 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-12T15:40:13+00:00Added an answer on June 12, 2026 at 3:40 pm

    This is really just a MAX() aggregate, grouping by etud and mod:

    SELECT
      etud,
      MAX(sess) AS sess,
      mod
    FROM yourtable
    GROUP BY etud, mod
    

    Update after edited quetsion:

    Although MySQL will allow you to simply add the column to the query above without adding it to the GROUP BY, the value you get for that column is non-deterministic and if you have multiple possible values, you can’t plan on which one you’ll get back (usually it will be the first one though).

    To pull in the remaining eta column matching the MAX(sess) you can join against a subquery.

    SELECT
      main.etud,
      maxsess.maxsess AS sess
      main.mod,
      main.eta
    FROM
      yourtable
      JOIN (
        SELECT
          etud,
          MAX(sess) AS maxsess,
          mod
        FROM yourtable
        GROUP BY etud, mod
        /* JOIN all 3 columns of the subquery which gets the MAX() against the rest of the table */
      ) maxsess ON main.etud = maxsess.etud AND main.sess = maxsess.maxsess AND main.mod = maxsess.mod
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little SQL but I can't find the way to get back
I've encountered a little problem selecting only the needed model in QueryOver. Here my
I'm a little new to SQL and have come across the following problem. I
I have a little DB challenge for you. Hopefully you can help. The Problem:
I have a little problem I can't figure out how to solve. I have
got a little problem im hoping someone can enlighten me on. Trying to serialise
coders. I'm running a little problem here and can't find the solution. I'm building
I can use the following code for tiny little queries: DECLARE @sql VARCHAR(8000) SET
I'm still a little new to Linq-To-SQL and I'm having a problem when I
I'm having a little problem getting SQL Server returning the same results as Oracle

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.