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

The Archive Base Latest Questions

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

let’s assume we have two tables table1 ———————- |ID | Date | ———————- |1

  • 0

let’s assume we have two tables

table1
    ----------------------
    |ID         | Date   |
    ----------------------
    |1          |20110101|
    |1          |20110102|
    |1          |20110103|
    |2          |20110102|
    |2          |20110103|
    |2          |20110104|
    ----------------------

table2
    ----------------------
    |ID2        |val     |
    ----------------------
    |1          |152     |
    |2          |155     |
    ----------------------

Using this query

SELECT * FROM table1, table2
WHERE table1.ID = table2.ID2
GROUP BY table1.ID 
ORDER BY DATE DESC

Mysql should return this

-------------------------------------------
|ID         |date    |ID2        |val     |
-------------------------------------------
|1          |20110103|1          |152     |
|2          |20110104|2          |155     |
-------------------------------------------

In Oracle I get this error:
ORA-00979: not a GROUP BY expression

EDIT:
The MAX function on the column Date does not work because this column is varchar(200)
The database/tables structure is not mine and I cannot alter it.

  • 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-26T09:12:20+00:00Added an answer on May 26, 2026 at 9:12 am

    You need to do one of two things…

    • GROUP BY and use aggregate functions to consolidate multiple records down to one
    • Use some lookup to identify the one record you want from the group

    In your case, you don’t just want a MAX() from table1, as it may be possible that a higher id has a lower date. In that case, I’d be inclined to use a lookup system…

    WITH
      ordered_table1 AS
    (
      SELECT
        ROW_NUMBER() OVER (PARTITION BY id ORDER BY date_field DESC) AS sequence_number,
        *
      FROM
        table1
    )
    SELECT
      *
    FROM
      ordered_table1
    INNER JOIN
      table2
        ON table2.id = ordered_table1.id
    WHERE
      ordered_table1.sequence_id = 1
    

    NOTE: This assumes your date is formatted such that alphanumeric ordering WILL yield the correct date order. If that is NOT the case (and d-m-yyyy will not order correctly), you need to replace date_field with TO_DATE(date_field) to ensure the correct order.

    NOTE: Use of TO_DATE(date_field) will also probably fix your MAX() problems.

    NOTE: If you want to store dates as strings, but them to be order friendly, use yyyy-mm-dd

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

Sidebar

Related Questions

Let's assume, you have the xml below. The goal is to group by FirstName
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let me try to explain what I need. I have a server that is
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's suppose I have a Discussion model, and that a discussion can be tagged.

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.