Results 1 to 6 of 6

Thread: MySQL GROUP BY *RESOLVED*

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    MySQL GROUP BY *RESOLVED*

    I can't see why the following SELECT statement won't work - any ideas?

    Code:
    SELECT				s.subject_id, s.subject_name
    FROM				tbl_subjects AS s
    INNER JOIN			tbl_lessons AS l
    ON				s.subject_id = l.subject_id
    WHERE 				l.online = 'True'
    GROUP BY			s.subject_id, s.subject_name
    ORDER BY			s.subject_name ASC
    The error I get is:

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [MySQL][ODBC 3.51 Driver][mysqld-3.23.55-nt]You have an error in your SQL syntax near 'BY s.subject_name ASC' at line 1

    /html/newLogin.asp, line 23


    Stumped again...

    DJ
    Last edited by dj4uk; Jul 13th, 2005 at 05:15 AM.

    If I have been helpful please rate my post. If I haven't tell me!

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MySQL GROUP BY

    How about this?

    Code:
    SELECT              s.subject_id, s.subject_name
    FROM                tbl_subjects AS s
    INNER JOIN          tbl_lessons AS l
    ON                  s.subject_id = l.subject_id
    WHERE               l.online = 'True'
    ORDER BY            s.subject_name ASC
    GROUP BY            s.subject_id, s.subject_name
    The sql below works for me...

    Code:
    SELECT 		VS.VS_Vessel, SS.SS_CarrierCode
    FROM 		SS 
    INNER JOIN 	VS 
    ON 		SS.SS_RefNum = VS.VS_RefNum
    GROUP BY 	VS.VS_Vessel, SS.SS_CarrierCode
    ORDER BY 	SS.SS_CarrierC
    Last edited by dee-u; Jul 13th, 2005 at 05:10 AM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: MySQL GROUP BY

    Now I get:

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [MySQL][ODBC 3.51 Driver][mysqld-3.23.55-nt]You have an error in your SQL syntax near 'GROUP BY s.subject_id, s.subject_name ' at line 1

    /html/newLogin.asp, line 23


    I'm pretty sure the GROUP BY has to come first.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  4. #4

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: MySQL GROUP BY

    Got it working:
    Code:
    SELECT				tbl_subjects.subject_id, tbl_subjects.subject_name
    FROM				tbl_subjects
    INNER JOIN			tbl_lessons
    ON				tbl_subjects.subject_id = tbl_lessons.subject_id
    WHERE 				tbl_lessons.online = 'True'
    GROUP BY			tbl_subjects.subject_id, tbl_subjects.subject_name
    ORDER BY			tbl_subjects.subject_name ASC
    It didn't seem to like the table aliases!

    Thanks for the suggestions.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MySQL GROUP BY *RESOLVED*

    This works too....

    Code:
    SELECT VS.VS_Vessel, SS.SS_CarrierCode
    FROM SS INNER JOIN VS ON SS.SS_RefNum = VS.VS_RefNum
    GROUP BY VS.VS_Vessel, SS.SS_CarrierCode
    ORDER BY  SS.SS_CarrierCode ASC;
    Why don't you try removing this line...

    Code:
    WHERE 				l.online = 'True'
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MySQL GROUP BY *RESOLVED*

    What happened? Why is it resolved already?

    Ooooppsss.... I missed Post #4.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

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



Click Here to Expand Forum to Full Width