Jump to content

Retreiving last row of records, if it is the most recent?


Recommended Posts

Ok, so I really didnt know how to title that subject!

 

I have a very simple table, which essentially is for a simple application where a user can 'own' another user, and someone else can then steal ownership off of that user.

 

The 3 field table is:

 

sender (a userID)

owner (a userID)

time

 

All steals/ownerships have to be recorded for counting purposes.

 

I have a page that looks up who that specific user currently owns, and at present I use:

 

SELECT DISTINCT *  FROM ownership WHERE sender='675490779' GROUP BY owner,sender limit 0,10

 

But this of course only shows anyone that they have owned previously, rather than who they currently own if no-one else has stolen since.

 

I need that query to be written such that it retreives the row, but only if they are the most recent owner when sorted by time.

 

Does this make any kind of sense, have I made a simple problem confusing?

 

Thanks for any help in advance

 

Scott

 

 

 

 

First, you don't need DISTINCT and GROUP BY.

Second, you can't ask for the records to be group in any particular order.

Third, why not get back the current owners and then filter by that sender?  Otherwise, I guess you could do it the other way, and check for any newer owners with a join.

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.