2017-08-24 71 views
0

我有兩個tables.College_Infra_items和College_infrastructure.The College_Infra_items有以下結構在angularjs

col_infraId requiredSeat available  collegeInfrastructureId 
     1   100    150     1 
     2   200    180     2 

College_infrastructure有以下結構上裝載

collegeInfrastructureId type name 
     1     UGC  Land Requirement(In acres) 
     2     UGC  Class rooms 
     3     AICTE Total Area 
     4     AICTE Loans 

現在,在我的html我是在重複顯示多表數據College_infrastructure詳細信息。 我正在寫類型的條件。也就是說,如果它是UGC類型,那麼College_infrastructure的前兩行細節將加載。如果AICTE接下來兩個。 這裏是我的html

在表格格式中,我顯示detailss.tbody節我重複College_infrastructure表只爲「名稱」列。但我無法得到requiredSeat的詳細信息,因爲在查詢中我沒有執行與College_infraItem表連接操作。

<tbody> 
    <tr role="row" class="even" data-ng-repeat="infraitem in 
    allInfraitemsByType"> 
    <td><strong>{{infraitem.name}}</strong></td> 
    <td><input type="text" 
    name="requiredseat" data-ng-model="infraitem.requiredseat"></td> 
    <td> 
    <input type="text" name="available" data-ng- 
    model="infraitem.available"></td> 
    <td class="text-center"><button type="submit" class="btn GreenBtn" 
    data-ng-click="saveInfrastructureDetails(infraitem)"><span 
    class="glyphicon glyphicon-ok"></span>Save</button></td> 
    </tr> 
    </tbody> 

查詢我寫這樣的

SELECT collegeInfrastructureId as collegeInfrastructureId,type as 
    type,name as name FROM college_infrastructure where type=:type 
    order by collegeInfrastructureId asc"; 

此查詢僅給了我College_Infrastructure table.But我想也是在同一查詢College_Infra_items的細節。 任何人都可以告訴我如何加入College_Infra_items這個查詢,以便在HTML重複我也可以參考College_Infra_items列。

回答

1
SELECT ci.collegeInfrastructureId as collegeInfrastructureId,ci.type as 
type,ci.name as name , 
    cli.requiredSeat 
    ... and some more fields you need 
FROM college_infrastructure ci 
    LEFT JOIN College_Infra_items cli ON cli.collegeInfrastructureId=ci.collegeInfrastructureId 
where type=:type 
order by ci.collegeInfrastructureId asc"; 

只需在您的查詢中使用INNER JOIN作爲第二個表。

UPDATE。更改INNER JOIN到LEFT JOIN

+0

如果有4行College_infrastructure表中所有屬於UGC那麼結果是隻顯示的列名其中有values.I要顯示UGC中的所有名稱都在College_infrastructure表中。如果值存在,那麼該值應該出現在表中,否則它應該顯示爲空。現在右邊只顯示有值的字段 –

+0

答案更新 – StanislavL

+0

是的。現在就來。謝謝 –

1

試試這個:

SELECT college_infrastructure.collegeInfrastructureId as collegeInfrastructureId,college_infrastructure.type as type,college_infrastructure.name as name ,College_Infra_items.requiredSeat 
FROM college_infrastructure left join College_Infra_items on College_Infra_items.collegeInfrastructureId = college_infrastructure.collegeInfrastructureId 
where type=:type 
order by collegeInfrastructureId asc"; 
+0

Woww ..非常感謝您 –

+0

歡迎您... – Nikita

+0

我已經使用了相同的查詢但我需要檢查哪裏條款where where where college_infrastructure.type =:type AND College_Infra_items.collegeId =:collegeId.Here我想顯示的數據滿足這兩個條件。但現在它只顯示填充數據。你可以告訴如何顯示來自college_infrastructure表的所有行以及它在College_Infra_items表中的任何數據? –