SQL Group BY

Results 1 to 2 of 2

Thread: SQL Group BY

  1. #1

    Default SQL Group BY

    Hi guys.<BR><BR>Could someone please rewrite this code so that it groups events by the ev.eventID column.<BR><BR>Ive been trying for the last hour or so without luck.<BR><BR>SQL = "SELECT reg.eventID, reg.userID, reg.reg_status, reg.howmany, ev.event_title, ev.ID, ev.eventID, ev.sublocation_select, ev.eventdate_masterSTART, ev.eventdate_masterFINISH, ev.location_select, ev.notes FROM registrations reg INNER JOIN events ev ON ev.ID = reg.eventID WHERE reg.userID = " & session("ID") & " AND ev.eventdate_masterSTART &#062; " & cdbl(now) & "AND reg.reg_status &#060;&#062; 4 AND reg.reg_status &#060;&#062; 2"<BR><BR>Thanks,<BR>John

  2. #2
    Join Date
    Dec 1969

    Default Nope...just ORDER BY

    There&#039;s almost always no reason to use GROUP BY unless you are using an AGGREGATE FUNCTION (such as MAX(), COUNT(), AVG(), SUM(), etc.) in the SELECT.<BR><BR>You aren&#039;t doing that here, so I would bet that all you need/want is an ORDER BY.<BR><BR> ORDER BY reg.eventID<BR><BR>Or ORDER BY as many fields as you like to force sub-ordering.<BR><BR>Using GROUP BY still wouldn&#039;t affect how the list of records would appear, just how they are grouped, so ORDER BY is simpler and cleaner.<BR>

Posting Permissions

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