Jump to content

Distinct One of Multiple Columns + Order


codefossa

Recommended Posts

Okay, so what I'm trying to do is select the newest review for each movie.  The table looks like this.

 

movieidusernametimestamp

515Pirategirl1317681086

314KatieLee1316868469

413gypsygrl22821316747249

212Kira1316086506

311Pirategirl1316037234

110jon2271315739335

29Pirategirl1315541865

28critical0glitch1315507796

27KatieLee1315438818

15Ozzy1314759243

14Kira1314755101

13peacemaker50001314754319

12critical0glitch1314753505

11Pirategirl1314748843

 

Here's one of many attempts that end up returning every row.

 

SELECT `y`.`movie`, `id`, `username`, `timestamp`
FROM `reviews` `x`
RIGHT JOIN (SELECT DISTINCT `movie` FROM `reviews`) AS `y`
ON `x`.`movie` = `y`.`movie`
ORDER BY `id` DESC

 

Also, if I use GROUP, it will return the oldest reviews instead of the newest.

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.