我有两张桌子.College_Infra_items和College_infrastructure。College_Infra_items有以下结构
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
在表格格式中,我显示详细信息。在tbody部分,我只重复了“name”列的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表。但是我也想在同一个查询中找到College_Infra_items的详细信息。 任何人都可以告诉我如何使用此查询加入College_Infra_items,以便在html重复中我也可以参考College_Infra_items列。
答案 0 :(得分: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。
更新。将INNER JOIN更改为LEFT JOIN
答案 1 :(得分: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";