Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join Problem

Status
Not open for further replies.

dagger2002

Programmer
Nov 23, 2004
172
US
Hello every one
I am working on a query set that needs to sort the data 3 times. Here are the existing query sets:

Code:
//	Builds Class Query
//	$query99 = "SELECT * FROM class WHERE cour_id = " . $row[cour_id] . " AND clas_active = 1 ORDER BY clas_sTime ASC";
	$query99 = "SELECT * FROM class WHERE cour_id = " . $row[cour_id] . " AND clas_active = 1 ORDER BY schoo_cdsCode ASC";
	$result99 = mysql_query($query99) or die/*(mysql_error());//*/("Class Problem Query");

	$numRows99 = mysql_num_rows($result99);
	$row99 = mysql_fetch_array($result99);
	
//	Builds School Query
	$queryCDS = "SELECT * FROM school WHERE  cdsCode = " . $row99[schoo_cdsCode];
	$resultCDS = mysql_query($queryCDS) or die/*(mysql_error());//*/("No Classes available at this time. Please try again later.");

	$numRowsCDS = mysql_num_rows($resultCDS);
	$rowCDS = mysql_fetch_array($resultCDS);

//	Builds District

	$queryDist = "SELECT * FROM district WHERE  cdsCode = " . $rowCDS[dist_cdsCode];
	$resultDist = mysql_query($queryDist) or die/*(mysql_error());//*/("No Classes available at this time. Please try again later.");

	$numRowsDist = mysql_num_rows($resultDist);
	$rowDist = mysql_fetch_array($resultDist);

The table structure goes like this

Code:
  District :|: School :|: Class :|: Course

and here is what i have tried for my join but am getting a 1064 error

Code:
SELECT 
	class.clas_id, class.clas_semester, class.clas_sMonth, class.clas_sDay, class.clas_eMonth, class.clas_eDay, class.clas_sTime, class.clas_eTime, class.clas_dayM, class.clas_dayT, class.clas_dayW, class.clas_dayTH, class.clas_dayF, class.clas_dayS, class.clas_blo, class.clas_active, class.cour_id, class.schoo_cdsCode, 
	course.cour_id, course.cour_Code, course.cour_name, course.cour_description, course.cour_hours, course.cour_hrExt, course.cour_note, course.cour_preReq, course.cour_active, course.sect_id
	school.schoo_id, school.cdsCode, school.dist_cdsCode, school.sname, 
	district.dist_id, district.cdsCode, district.dist_name, district.phone

FROM `class` LEFT JOIN `school` ON class.schoo_cdsCode = school.cdsCode

FROM `school` left join school.dist_cdscode = district.cdsCode
WHERE class.cour_id = 1 AND class.clas_active = 1

Thanks all in advanced
 
Ok all i have tried a join and am getting this any ideas?

1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '. schoo_id , school . cdsCode , school . dist_cdsCode , school

with this join statement

Code:
SELECT class.clas_id, class.clas_semester, class.clas_sMonth, class.clas_sDay, class.clas_eMonth, class.clas_eDay, class.clas_sTime, class.clas_eTime, class.clas_dayM, class.clas_dayT, class.clas_dayW, class.clas_dayTH, class.clas_dayF, class.clas_dayS, class.clas_blo, class.clas_active, class.cour_id, class.schoo_cdsCode, course.cour_id, course.cour_Code, course.cour_name, course.cour_description, course.cour_hours, course.cour_hrExt, course.cour_note, course.cour_preReq, course.cour_active, course.sect_id school.schoo_id, school.cdsCode, school.dist_cdsCode, school.sname, district.dist_id, district.cdsCode, district.dist_name, district.phone
FROM  `class` 
LEFT JOIN  `course` ON class.cour_id = course.cour_id
LEFT JOIN  `section` ON course.sect_id = section.sect_id
LEFT JOIN  `school` ON school.cdsCode = class.schoo_cdsCode
LEFT JOIN  `district` ON district.cdsCode = school.dist_cdsCode
ORDER BY district.dist_name, school.sname, class.clas_sTime
 
If you have actually cut&pasted, then there appears to be a comma missing after course.sect_id - it should read
Code:
SELECT class.clas_id, class.clas_semester, class.clas_sMonth, class.clas_sDay, class.clas_eMonth, class.clas_eDay, class.clas_sTime, class.clas_eTime, class.clas_dayM, class.clas_dayT, class.clas_dayW, class.clas_dayTH, class.clas_dayF, class.clas_dayS, class.clas_blo, class.clas_active, class.cour_id, class.schoo_cdsCode, course.cour_id, course.cour_Code, course.cour_name, course.cour_description, course.cour_hours, course.cour_hrExt, course.cour_note, course.cour_preReq, course.cour_active, course.sect_id[COLOR=red][b],[/b][/color] school.schoo_id, school.cdsCode, school.dist_cdsCode, school.sname, district.dist_id, district.cdsCode, district.dist_name, district.phone
FROM  `class`
LEFT JOIN  `course` ON class.cour_id = course.cour_id
LEFT JOIN  `section` ON course.sect_id = section.sect_id
LEFT JOIN  `school` ON school.cdsCode = class.schoo_cdsCode
LEFT JOIN  `district` ON district.cdsCode = school.dist_cdsCode
ORDER BY district.dist_name, school.sname, class.clas_sTime

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top