Java 如何合并两个查询的结果
我有一个类似的问题Java 如何合并两个查询的结果,java,mysql,Java,Mysql,我有一个类似的问题 SELECT class_id,student_id,title,location FROM class AS c INNER JOIN library AS l ON (l.student_id = c.student_id) group by class_id,student_id; 输出: class_id student_id title location 1 mac smart 2ndfloor
SELECT class_id,student_id,title,location
FROM class AS c
INNER JOIN library AS l
ON (l.student_id = c.student_id)
group by class_id,student_id;
输出:
class_id student_id title location
1 mac smart 2ndfloor
1 john smart 2ndfloor
1 charles smart 2ndfloor
2 james hard 1stfloor
另一个问题
SELECT school_id,class_id,s.title FROM school
输出:
school_id class_id title
1 1 school1
1 1 school1
1 2 school1
我必须先显示学校记录,然后显示该学校的班级(即)
我怎样才能做到这一点,请告诉我它可以在mysql本身中完成,或者我需要使用java列表迭代器来进行迭代。我使用的是mysql数据库和java。您可以在SQL查询中使用Union来合并两个结果 奥莱尔斯
在代码中,您可以选择一些父子网格视图。在应用程序级/表示层处理表示逻辑,例如,一个简单的PHP循环,或者,大概是一点java。将查询或循环编码结合起来
school_id class_id title
1 NULL school //here school title and id
1 1 2ndfloor //here classes in that school
2 NuLL school2 //here next school title and id
2 1 2ndfloor //here classes in the next school