GROUP_CONCAT is an RDBMS-specific function. Some others don't have it, some do, and then under other names.

Anyway, the use of id is redundant and, for that matter, probably wrong, assuming i'm understanding the layout correctly.

line_n groups all words in any given line together. word_position defines their order. id is the order in which they are inserted into the table. As it so happens, lines and words are inserted in order so id can be used as a surrogate for word_position to define the order. However, should a word be inserted out of order, a word_position be updated, or (a rare cases that applies only in some situations) the ids be reused, the usage of id may produce incorrect results. In any case, line_n and word_position will always be correct.

The recursive query above should work. It has been modified to squelch the non-finished lines (via the MAX in the anchor). If the in-progress lines are desired, it is a simple modification.


In reply to Re^5: Fetching data from DB and complex data structures by chacham
in thread Fetching data from DB and complex data structures by frasco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.