tricky SQL when joining

Posted by Erik on Stack Overflow See other posts from Stack Overflow or by Erik
Published on 2010-03-27T23:44:55Z Indexed on 2010/03/27 23:53 UTC
Read the original article Hit count: 249

Filed under:
|

I've two tables, shows and objects. I want to print out the latest objects, and the shownames for them. Right now I'm doing it this way:

SELECT MAX(objects.id) as max_id, shows.name, shows.id 
FROM shows, objects 
WHERE shows.id = objects.showId
GROUP BY shows.name 

however, if I also want to fetch the episode of the object I can't put it like SELECT object.episode [...], because then wont automatically select the object which is MAX(objects.id), so my question is how to do that?

If you haven't already figured out my tables they're like this:

  • Shows
    • id
    • name

and also:

  • Objects
    • id
    • name
    • episode
    • season
    • showId

Using MySQL. Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql