Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: MySQL question

by Kozz (Friar)
on Mar 28, 2002 at 22:21 UTC ( #155136=note: print w/ replies, xml ) Need Help??


in reply to Re: MySQL question
in thread MySQL question

In the spirit of sportsman-like conduct, I ++'ed your post. Mostly the reason I venture to ask this question here is because it's a reasonable forum with intelligent persons of moderate tempers. ;) I don't get along with usenet very well, some IRC channels seem to smack of elitism, and don't know of any other online forums that would be better suited to answer my question.

Anyhow, to answer your question, I was hoping to get one row per distinct doc_num whose version was the max() of all versions for that doc_num, and whose title corresponded to the record with the max version:

title | doc_num | version -------+---------+-------- foo | 1234 | 2 baz | 5678 | 1
Compare my chart above to the "original" and you may see what I mean.

Anyhow, my apologies for tempting fate in this manner. If I've overstepped my bounds by replying to your post, I once again apologize. But if you find the breath to chastize me once more, I also welcome links to any Database-related forums. ;)


Comment on Re: Re: MySQL question
Download Code
•Re: Re: Re: MySQL question
by merlyn (Sage) on Mar 28, 2002 at 22:28 UTC
    Ahh. Then again, with a real database with subselects, that'd be:
    SELECT title, doc_num, version FROM atable WHERE (doc_num, version) IN ( SELECT doc_num, MAX(version) FROM atable GROUP BY doc_num );
    Again, this won't work in puny MySQL. PostgreSQL or better, baby!

    -- Randal L. Schwartz, Perl hacker

      If Kozz cannot upgrade to PostgreSQL for some reason couldn't Kozz ape a subselect with by creating a tempory table "ttable" and then join "atable" with that? sonething like this ...
      create table ttable as SELECT doc_num, MAX(version) FROM atable GROUP BY doc_num; SELECT title, doc_num, version FROM atable a, ttable t WHERE a.doc_num = t.doc_num and a.version = t.version;

      ... I don't know about the other monks I find SQL
      fun like its a weird puzzle.
Please delete me
by NodeReaper (Curate) on Mar 29, 2002 at 06:40 UTC

    Reason: (Jazz) Delete - by author (me) request

    For more information on this node visit: this

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://155136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-11-29 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls