如何在一个查询中编写asc

时间:2016-03-23 15:01:47

标签: php mysql sql

我写了这个查询,但没有成功,写作asc and跟着对方有问题。

我如何解决这个问题?

$q = "SELECT * FROM coe_courses LEFT JOIN equal_coe ON
 equal_coe.course_number=coe_courses.course_number 
LEFT JOIN student_record ON coe_courses.course_number=
student_record.course_number order by student_record.course_number asc AND student_record.id=". $_SESSION['user_id'];

1 个答案:

答案 0 :(得分:0)

您的SQL查询需要重新排列以使用WHERE子句,如下所示:

$q = "SELECT * FROM coe_courses 
      LEFT JOIN equal_coe ON equal_coe.course_number=coe_courses.course_number 
      LEFT JOIN student_record ON coe_courses.course_number=student_record.course_number 
      WHERE student_record.id=". $_SESSION['user_id'] ."
      order by student_record.course_number asc";