Jump to content

Getting list of most recently updated rows in table - mysql syntax help


harleydude

Recommended Posts

I have a table with some data like this:

Type Null Default
cpindex  int(6) No   
cpid  int(3) No  0 
cpcid  int(3) No  0 
cpcust  varchar(30) No  0 
cprsm  char(3) No   
cpprice  float No  0 
cpqty  int(9) No  0 
cpdate  date No  0000-00-00 
cpquote  int(3) No  0 

Indexes: Keyname Type Cardinality Field
cpindex  INDEX None  cpindex 
cpid 
cpcid  INDEX None  cpcid 
cpid  INDEX None  cpid 

very simple data table, now the users have populated it with various amounts of data where the application will set the date to the current date (date data was enterred:Y-m-d format). So we have loads of data in the table where common items may have multiple entries on different days (we won't talk about multiple entries on the same day... users, egads!!). Ok, so far so good.

Now, what I need to do is look at this database and get all of the most recent entries, en mass. The criteria to get the recordset is:
cpid - product id
cpcid - customer id

i need all records with the most recent date by product group. What is the most efficient method of doing this?

(using the select max(cpdate), * from cptable where cpid= $val and cpcid = $cval does not work).

Thanks guys.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.