in reply to Re: Perl DBI fetchall_arrayref - puzzling behaviour
in thread Perl DBI fetchall_arrayref - puzzling behaviour

Thank you so much, gellyfish! You're abolutely right :) I added the ALL and now I get both numbers when the are the same. But, if you don't mind, what's the difference between UNION and UNION ALL?

Thanks once again and cheers,

Update:

From MySQL FAQ

If you don't use the keyword ALL for the UNION, all returned rows will be unique, as if you had done a DISTINCT for the total result set. If you specify ALL, you will get all matching rows from all the used SELECT statements.

  • Comment on Re^2: Perl DBI fetchall_arrayref - puzzling behaviour

Replies are listed 'Best First'.
Re^3: Perl DBI fetchall_arrayref - puzzling behaviour
by dragonchild (Archbishop) on Jul 16, 2004 at 13:27 UTC
    Think in terms of sets. A set is, mathematically, a bunch of unique items. So, when you union two sets, you take all the unique items that appear in either set. '2' already appeared, so it won't be added again the second time its seen. (It's not exactly like that, but that's the basic idea.)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Thanks, dragonchild!

      I found the MySQL faq which explains the difference. But yours added a different dimension to it which makes it clearer :)

Re^3: Perl DBI fetchall_arrayref - puzzling behaviour
by gellyfish (Monsignor) on Jul 16, 2004 at 13:33 UTC

    I think it would be easier to quote the documentation:

    UNION Specifies that multiple result sets are to be combined and returned as + a single result set. ALL Incorporates all rows into the results, including duplicates. If not s +pecified, duplicate rows are removed.

    /J\

    janitored by ybiC: Replace <pre> tags with <code> to avoid lateral scrolling