现在的位置: 首页 > 综合 > 正文

关于多值查询

2012年07月24日 ⁄ 综合 ⁄ 共 582字 ⁄ 字号 评论关闭

我在做实现家庭礼物显示的用户控件,表设计是这样的:
Users(用户表)
  UserId,UserName,UserPassword,UserFamilyId(家庭表FamilyId的外键),...
Family(家庭表)
  FamilyId,FamilyName,...
Present(礼物表)
  PresentId,PresentName,PresentUrl,...
Present_list(用户拥有礼物表)
  UserId,PresentId,...
我进入家庭后利用FamilyId传值到Family.aspx页面,想在这个页面显示FamilyId对应家庭的所有礼物显示出来,我利用两个嵌套子查询语句:com.CommandText = "select * from Present where PresentId=( select PresentId from Present_list where UserId=(select UserId from Users where UserFamilyId='" + FamilyId + "'))";
它提示错误说:子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。

================================================
老师回答:PresentId in就可以

抱歉!评论已关闭.