|
-
Jul 13th, 2005, 04:50 AM
#1
Thread Starter
Frenzied Member
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!
-
Jul 13th, 2005, 05:04 AM
#2
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.
-
Jul 13th, 2005, 05:12 AM
#3
Thread Starter
Frenzied Member
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!
-
Jul 13th, 2005, 05:14 AM
#4
Thread Starter
Frenzied Member
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!
-
Jul 13th, 2005, 05:16 AM
#5
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'
-
Jul 13th, 2005, 05:20 AM
#6
Re: MySQL GROUP BY *RESOLVED*
What happened? Why is it resolved already? 
Ooooppsss.... I missed Post #4.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|