Tricky, SQL grouping

Results 1 to 2 of 2

Thread: Tricky, SQL grouping

  1. #1
    william Guest

    Default Tricky, SQL grouping

    I have, say 100 records with fields: heading, sub-heading, location. I do a "group by" query to return them in order. However, as I display them, I do not want to see dupes for heading and sub-heading. Can I do this and still loop through recordset(s)? Do I need to return recordsets per sub-group? Currently, I&#039m returning a recordset for each sub-group but I think there has to be a more efficient way. Display should look like this:<BR><BR>heading1<BR> sub-heading1<BR> location<BR> location<BR> location<BR> sub-heading2<BR> location<BR> location<BR>heading2<BR> etc<BR><BR>Any ideas? Thanks.

  2. #2
    Richard A. Lowe Guest

    Default RE: Tricky, SQL grouping

    If you use the GROUP BY clause, you shouldn&#039t see duplicates for the fields you GROUP BY:<BR><BR>SELECT field1, field2, count(field3) <BR>FROM table1<BR>GROUP BY field1, field2<BR><BR>In the above field1 will be totally distinct and field2 will be distinct within the unique field1 values - make sense?? So if field1 is the States and field2 cities, Califonia may show a sub-heading of Springfield, but so will Missouri etc. etc.<BR><BR>Richard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts