l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Jul 21 05:02

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] SQL help - unions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] SQL help - unions

On Wed, Jul 21, 2004 at 12:00:39AM -0700, Jeff Newmiller wrote:
> A headcount is not the same as a roster... neither Peter's nor
> Michael's version was counting anything.

I assumed what Peter was after was a list of unique SSN's for "race = 0"
students in Fall_2003 and Spring_2004.

> In fact, Michael's version is just wrong.  He uses an open join,

[ SELECT distinct SSN from Fall_2003, Spring_2004 where race = 0; ]

I think you mean an INNER or CROSS join (the cartesian product).

> which is different than a union join.

A UNION is not a join, it's a combination of results from separate
queries where the number and type of columns are the same.  You actually
can prevent eliminating duplicates with UNION ALL, but that's not what
you want in this case.

> 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.

You are correct, and you will get an error due to the ambiguous "SSN"

> 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).

Well not really because of the use of DISTINCT...

Maybe a NATURAL join would work, but the UNION method is the most

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!