[V4RB] GROUP BY Recid Problems

Frank Schima macsforever2002 at yahoo.com
Fri Feb 7 08:33:38 CST 2003


Hi Jeb,


--- jeb eddy <jebeddy at ix.netcom.com> wrote:
> Forgive my ignorance, but why would you want to do a GROUP BY on the 
> primary key?  By definition, all the values are unique, so GROUP BY 
> should return exactly the same set of records, right?
> 
> The system should not crash, but this GROUP BY performs no useful 
> function?  Please correct me if I am misunderstanding something.

It makes no sense for a single table, I was just showing Ruslan an easy way to see and
debug the problem. However when doing multi-table JOINs, it can be very useful. 

Let me try to give you an example off the top of my head:

Table 1 = Student holds Students
Table 2 = Class contains Classes 
Table 3 = StudentClass and is a M:M table linking Students to Classes

The Student table has a Name field
The Class table has a Name field too. 
The StudentClass table links to the other 2 tables with Object Pointers. 

How many students are in every Class?

   SELECT Class.Recid, count(*)
   FROM Class, StudentClass
   GROUP By Class.Recid

Of course I could do this from the StudentClass table directly, but what if I want to
also print out the Name of the Class and the Recid?

   SELECT Class.Recid, Class.Name, count(*)
   FROM Class, StudentClass
   GROUP BY Class.Recid, Class.Name

In any event, Valentina should not crash on any SQL statement, whether useful or not! :^)


Best Regards,
Frank


=====
Frank Schima                <mailto:frank at labrecyclers.com>
Lab Recyclers Inc.          <http://www.labrecyclers.com/>
Gaithersburg, MD USA        <http://www.ci.gaithersburg.md.us/>

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


More information about the Valentina mailing list