realbasic-nug
[Top] [All Lists]

Re: Re: Re: SQL Select

To: "REALbasic NUG" <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Re: Re: SQL Select
From: "Sean McCollum" <seanmccollum at gmail dot com>
Date: Mon, 31 Jul 2006 10:38:15 -0500
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=BKNKUIIDsNXaAXvc16pE0CAGYEyAuJ3qKxltVEhKa0rNWKnE/RHLXFb2hspF51Cs5vzB1VC5XPfdmlkGjAYNJSFNeMpjgABpQYwaNUBfnlMxJFUgUrxfnGjVsATlRrTPPBpcEAqmuSwP80xi1eAvclSW9/+tfO8UPwanja1pJYg=
References: <2aed194a0607281134o74d5b0b1o301f7456a5562795 at mail dot gmail dot com> <C0F04607 dot 11AF3%REALbasicNUG2003 dot 001 at toolbox dot uk dot com> <2aed194a0607281507n563ddc17icbde3feb3c779bf2 at mail dot gmail dot com>
Hello all. I inadvertently sent some of my replies on Friday to
individuals and not back to the nug. Whoops. Thanks for all of the
replies. I've gotten some great help from the nug. I've learned a few
cool things, but I haven't yet figured out my original problem.

Here's the situation:

Table: class  Columns: name, id (both VARCHAR)
Table: student - Columns: name, id (both VARCHAR)
Table link - Columns: pid, cid (both VARCHAR) This table links
students and classes

Class A has Sean, Narinder, Max, Norman
Class B has Mary, Jane, Narinder, Norman
Class C has Sean, Sally

Here's what I have working so far. I'm able to get every student who's
in EITHER class A or class B. using this code:

SELECT DISTINCT person.name FROM person, class, link WHERE
link.pid=person.id AND link.cid=class.id AND class.id IN ("A", "B")
Results: Sean, Narinder, Max, Norman, Mary, Jane

Or using this code:

SELECT DISTINCT person.name FROM person, class, link WHERE
link.pid=person.id AND link.cid=class.id AND (class.id = "A" OR
class.id = "B")
Same Results: Sean, Narinder, Max, Norman, Mary, Jane

I can also get any student who is in more than one class (but not
class specific) using this code:

SELECT  person.name FROM person WHERE (SELECT COUNT(*) FROM link WHERE
link.pid=person.id)>1
Results: Sean, Narinder, Norman

Or, similarly, I can also get any student who is in exactly two
classes (but not class specific) using this code (only change >1 to
=2):

SELECT  person.name FROM person WHERE (SELECT COUNT(*) FROM link WHERE
link.pid=person.id)=2
Results: Sean, Narinder, Norman

What I'm still after is only students in a specific set of classes.
For example - A & B. (A recordset containing only Narinder and Norman
is what i'd want - They are the only two students who are in both
classes A & B) I've tried various forms of GROUP BY and COUNT, but I
haven't been able to get any results.

Learning is fun. I feel I'm close. Hopefully, this will help people in
the future as well since this kind of structure is used so often in
databases: actors and movies, songs and artists, etc.

Thanks,
--
Sean McCollum
Mac OS 10.4.7
RB 2006 r3 Pro
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>