我基本上想通過外鍵的條目列來排序特定的查詢結果。下面是我的表:mySQL ORDER BY using FOREIGN KEYS
class
------
classId
profId //Points to a profId from professor table
courseId //Points to a specific courseId from course table
semId //Points to a specific semId from semester table
professor
---------
profId
first //first name
last //last name
course
------
courseId
department //The `CMSC` in CMSC101
number //The `101` in CMSC101
title
semester
--------
semId
season //example: Spring, Summer, Fall
year
我希望他們能夠hierarchally有序,而且通過在類列的列的外鍵。所以,我SELECT
全部來自class
條目和順序進行排序:
- 課程 - >部門
- 課程 - >數字
- 課程 - >部分
- 教授 - >最後
- 教授 - >第一
- 學期 - >年
- 學期 - >賽季
這是一個相當簡單的'SELECT',所以首先要從文檔[這裏](http://dev.mysql.com/doc/refman/5.0/en/select.html )。如果上面的查詢有一個特定部分,那麼您很難理解,請讓我知道,我會盡力解釋。 – 2013-04-07 01:33:27
是否可以添加'WHERE professor.last ='Smith''並縮小該查詢的範圍,以僅顯示名爲「Smith」的教授的班級? – 2013-04-07 03:24:16
當然。你的語法是正確的;只是把它放在'INNER JOIN'和'ORDER BY'之前。 – 2013-04-07 04:11:10