[vox-tech] SQL help - unions
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Jul 21 00:00:39 PDT 2004
On Tue, 20 Jul 2004, David Hummel wrote:
> On Tue, Jul 20, 2004 at 06:20:06PM -0700, Jeff Newmiller wrote:
[...]
> > As the other respondents suggested, different SQL engines have different
> > levels of support for the language.
> >
> > SELECT SSN from [Fall 2003] WHERE race == 1
> > UNION
> > SELECT SSN from [Spring 2004] WHERE race == 1
>
> The comparison operator for equal is '=' not '=='.
Yes, I know, but this was in Peter's original, and I thought MySQL
supported this, so I left it alone.
> > gets you a little bit closer, but there are a couple of problems with
> > this... it isn't really obtaining a headcount,
>
> Yes it is. As is Michael Wenk's version.
A headcount is not the same as a roster... neither Peter's nor Michael's
version was counting anything.
In fact, Michael's version is just wrong. He uses an open join, which is
different than a union join. The former concatenates the columns to give
two distinct "SSN" columns and selects all possible pairings of the values
in these columns, and the columns must be referred to with table names to
distinguish them. Since he isn't constraining this open join, he ends up
with all possible pairings of SSN values (if there are 200 in the fall and
300 in the spring, then there are 60000 rows in his result).
> > and unions don't eliminate duplicates.
>
> Yes they do.
This was from my experience... and since I don't recall the exact
instance and the documentation agrees with you, I won't argue.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...2k
---------------------------------------------------------------------------
More information about the vox-tech
mailing list