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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:20:40+00:00 2026-05-25T13:20:40+00:00

To create a table, I am retrieving the data with the following query: SELECT

  • 0

To create a table, I am retrieving the data with the following query:

SELECT cId,cProductId,cDate,cInfo FROM tProduct ORDER BY cProductId ASC,cDate ASC;

Naturally I simplified the query a lot, but you get the notably, there might be many record for a same product, and the only one that interest me in the newest, thus how I order my query: I only store the information for the last row I encounter in my while loop.

while (($row = $result->fetch()) !== FALSE)
{
      if(!empty($row[0])){
          if(($table_row[1]!=$row[1])&&(!empty($table_row[0]))){
              //Display the last row saved
          }
          $table_row= array($row[0],$row[1],$row[2],$row[3]);
      }
}

Now I want to implement some sorting options for the html table which is generated. I’ll store the sorting information in a session variable. Amongst the sorting option, I want to be able to sort by date. How can I be sure to retrieve only the newest row for each product while ordering my query by date?

  • 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-25T13:20:40+00:00Added an answer on May 25, 2026 at 1:20 pm

    You didn’t include FROM clause in your query. However, assuming you want the newest row per product ID, you can do something like this:

    SELECT cId,cProductId,cDate,cInfo
    FROM tProduct t1
    WHERE cDate = (SELECT max(cDate) FROM tProduct t2 where t1.cProductID = t2.cProductId)
    ORDER BY cProductId ASC,cDate ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am retrieving data from a SQL table so I can display the result
I wish to create an external table in an Oracle database, retrieving its data
I am trying to write a query for retrieving data from SQLite database. I
I am retrieving some JSON data with the following function. It is called when
I'm trying to create a windows form application that manipulates data from several tables
I have created an sqlite table using the following statement: CREATE TABLE IF NOT
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
When retrieving a lookup code value from a table, some folks do this... Dim
I am facing some issues while retrieving data from a doctrine pager object! Let
The typical way of selecting data is: select * from my_table But what if

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.