两个表invoice和invoicedetail的视图查询出来的结果会重复三遍
这是本人的SQL语句·本人用的是navicat做的视图
这是本人的SQL语句·本人用的是navicat做的视图
select `invoice`.`invoiceId` AS `invoiceId`,`invoice`.`detailId` AS `detailId`,`invoice`.`creationDate` AS `creationDate`,`invoicedetail`.`type` AS `type` from (`invoice` join `invoicedetail`)
invoice和invoicedetail的关系是一对多的·
求高手解决
解决方案:60分
2个表关联,试试加上关联条件:
select `invoice`.`invoiceId` AS `invoiceId`,`invoice`.`detailId` AS `detailId`,
`invoice`.`creationDate` AS `creationDate`,`invoicedetail`.`type` AS `type`
from `invoice` join `invoicedetail` on 关联条件
假如是 实在是没有,那就只能用distinct了:
select distinct `invoice`.`invoiceId` AS `invoiceId`,`invoice`.`detailId` AS `detailId`,
`invoice`.`creationDate` AS `creationDate`,`invoicedetail`.`type` AS `type`
from `invoice` join `invoicedetail`
select `invoice`.`invoiceId` AS `invoiceId`,`invoice`.`detailId` AS `detailId`,
`invoice`.`creationDate` AS `creationDate`,`invoicedetail`.`type` AS `type`
from `invoice` join `invoicedetail` on 关联条件
假如是 实在是没有,那就只能用distinct了:
select distinct `invoice`.`invoiceId` AS `invoiceId`,`invoice`.`detailId` AS `detailId`,
`invoice`.`creationDate` AS `creationDate`,`invoicedetail`.`type` AS `type`
from `invoice` join `invoicedetail`