Need some SQL help

David A. Bandel david
Mon May 17 11:56:03 PDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 25 Nov 2003 08:52:46 -0500 (EST)
Net Llama! <netllama at linux-sxs.org> wrote:

> On Tue, 25 Nov 2003, David A. Bandel wrote:
> >
> > Folks,
> >
> > Any SQL gurus out there?
> >
> > I have a somewhat complex table structure that I need help with. 
> > Would require either left outer join or subselects, but it's a real
> > poser for me.  Working with postgresql.  Can discuss on or off line.
> >
> > TIA,
> >
> > David A. Bandel
> 
> Throw it at us, and see what we can do.

Well, I just beat it 5 minutes ago - after wrestling with this thing
half the nite and most of the morning.

Trick was, I was trying to use one query to join 4 tables.  Problem came
in when I used an aggregate function within a subselect to limit the
tuples returned.  Each select worked as it should, but when I tried to
use the select with the aggregate function as a subselect, it gave me an
error I couldn't resolve (apparently, you can't have multiple tuples
returned from an aggregate function in a subselect - aaaagh!).

Problem solved by creating two views, one from each select, and joining
the views.  Let the database do the work rather than the program.

Why was I limiting myself to one query?  Easier to work into a Perl
program web interface using CGI and DBI.  If I used temp tables and
forgot to destroy them (drop on commit), I'd leak away all the
resources.  Now to finish the interface and I'm done (hopefully before
late tonite).

Wish I worked on SQL tables more often - amazing what you forget.

Ciao,

David A. Bandel
- -- 
Focus on the dream, not the competition.
		Nemesis Racing Team motto
GPG key autoresponder:  mailto:david_key at pananix.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/w3w+j31PLQNUbV4RAtqjAJ0TIO+pNOXW36dR1Fc6QamRoRWCOACfUBdn
g5giE2umU1tiYtZe+VMx5VQ=
=O5jA
-----END PGP SIGNATURE-----


More information about the Linux-users mailing list