2013-10-25 88 views
0

我有一個像如何合併兩個querys結果

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; 

OUTPUT查詢:

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 

我必須首先表明了學校紀錄則顯示類在學校(即)

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 

我怎樣才能做到這一點,請一些我可以在MySQL本身完成或者我需要使用Java列表iterater迭代it.i我使用MySQL數據庫和Java。

+0

在應用程序級/表示層處理呈現邏輯,例如,一個簡單的PHP循環 - 或者,大概是一個java的smidge。 – Strawberry

+0

結合兩個查詢或循環密碼 – vijaykumar

+0

在sql中使用聯合 – Vijaychandar

回答

0

您可以使用聯盟在SQL查詢合併兩個結果..

否則容易

在代碼中,你可以去一些父子GridView的。