MYSQL多表联合查询&&排序

主要思想:先联合查询数据,再对查询结果按照某标签进行排序
code:

   String sql = "SELECT * FROM (SELECT task.idTask,task.task_name,task.author,task.effort,task.ToF,users.name,task_union_users.idUser"
     + " FROM task_union_users "
     + "join task on task_union_users.idTask=task.idTask "
     + "join users on task_union_users.idUser=users.student_id "
     + "WHERE users.student_id="+student_id
     +")AS a ORDER BY idTask DESC(或者ASC)";
     

注意事项:末尾一定要用AS a(一个量)!否则会执行失败

你可能感兴趣的:(MySQL数据库1)