加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB.Net程序设计:SQLite多表查询(关联多表)注意点

发布时间:2020-12-16 22:46:53 所属栏目:大数据 来源:网络整理
导读:在SQLite中要写一个多表查询,关联多表。 手工写的: select l.strLotNo,l.strLotName,l.strDescription,l.lngCatalogID,b.strCatalogBig,l.lngCatalogIDSnd,s.strCatalogSnd,l.lngMaterialID,m.strMaterial,l.strSize,l.strSUnit,l.dblWeight,l.strWUnit,l.

在SQLite中要写一个多表查询,关联多表。

手工写的:

select l.strLotNo,l.strLotName,l.strDescription,l.lngCatalogID,b.strCatalogBig,l.lngCatalogIDSnd,s.strCatalogSnd,l.lngMaterialID,m.strMaterial,l.strSize,l.strSUnit,l.dblWeight,l.strWUnit,l.dblPrice,l.strPUnit,l.dblClosingCost,l.strCPUnit,l.dblStock,l.lngAuthorID,a.strAuthor,l.dtmObjCreated,l.strPrize,l.dtmRsCreated,l.strRemarks from tblLot as l left join vCatBig as b on (tblLot.strLotNo=vCatBig.Bstrlotno and tblLot.lngCatalogID=vCatBig.Blngcatalogid) left join vCatSnd as s on (tblLot.strLotNo=vCatSnd.Sstrlotno and tblLot.lngCatalogID=vCatSnd.slngcatalogid) left join tblMaterial as m on (tblLot.lngMaterialID=tblMaterial.lngMaterialID) left join tblAuthor as a on (tblLot.lngAuthorID = tblAuthor.lngAuthorID) where tblLot.strStatus<>'Void'

老是执行不过。

再分小一点:

select l.strLotNo,b.catalogBig from tblLot as l join vCatBig as b on tblLot.strLotNo=vCatBig.strlotno and tblLot.lngCatalogID=vCatBig.lngcatalogid where tblLot.strStatus<>'Void'
还是不行。

按提示修改为更简单一点的:

select strLotNo,strLotName,lngCatalogID,strCatalogBig from tblLot as l join vCatBig as b on (l.strLotno=b.bstrLotNo )
结果可以运行了。

------------------

现在知道如果表有别名: as l 和 as b 关联字段要写明 l 或者 b ,不可以用原表名。

还有select 字段如果要选择两个表以上的字段,最好在每个字段前加上标的别名,如上面的

l.strLotNo,s.strCatalogSnd

最后重新修改原来那个多表关联查询,可以运行了。

CREATE VIEW [vLot] AS select l.strLotNo,l.strRemarks from tblLot as l left join vCatBig as b on (l.strLotNo=b.Bstrlotno and l.lngCatalogID=b.Blngcatalogid) left join vCatSnd as s on (l.strLotNo=s.Sstrlotno and l.lngCatalogID=s.slngcatalogid) left join tblMaterial as m on (l.lngMaterialID=m.lngMaterialID) left join tblAuthor as a on (l.lngAuthorID = a.lngAuthorID) where l.strStatus<>'Void'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读