尝试更多类似的东西:
SELECT c.user_id FROM database_all AS a
JOIN database_users AS u ON a.userid=u.userid2
JOIN database_courses AS c ON b.userid2=c.user_id
WHERE a.data='2013-09-03'
AND a.college='Harvard'
AND c.num_courses<3
通常你需要把你的WHERE
子句放在最后,它DBMS
会为你优化查询。
我实际上在这里有一个非常相似的问题。
MySQL 文档在其关于SELECT
语法的部分也对此进行了介绍。
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
如您所见,FROM
带有表引用的子句直接位于WHERE
子句之前。