我正在尝试从下面的查询中包含不同的表中获取列值,但是当我检查where子句中的不同条件时,它会给出错误。
sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_PostCode";
sql += "," + "members.member_Reference, members.member_Dob, members.member_IsBiometric, mshiptypes.mshipType_Name, mshipstatustypes.mshipStatusType_Name";
sql += "," + "membertomships.memberToMship_EndDate";
sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
sql += " "+"LEFT JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id";
sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
sql += " " + "WHERE memberToMship_PayMethod='Cash' AND mshipStausType_Name ='Live' AND mshipStatusType_Name = 'Defaulter' AND mshipStatusType_Name='Frozen'";
但它给出了这样的错误
Error Code: 1054
Unknown column 'mshipStausType_Name' in 'where clause'
任何人都可以帮助我,我正在使用mysql ...
这是修改过的查询,但是它没有提取它给出空列值的蚂蚁数据
sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_PostCode";
sql += "," + "members.member_Reference, members.member_Dob, members.member_IsBiometric, mshiptypes.mshipType_Name, mshipstatustypes.mshipStatusType_Name";
sql += "," + "membertomships.memberToMship_EndDate";
sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
sql += " "+"LEFT JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id";
sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
sql += " " + "WHERE membertomships.memberToMship_PayMethod='Cash' AND mshipstatustypes.mshipStatusType_Name='Live' AND mshipstatustypes.mshipStatusType_Name = 'Defaulter' AND mshipstatustypes.mshipStatusType_Name='Frozen'"
答案 0 :(得分:1)
如果列的拼写是正确的,那么我认为编译器没有确定该列属于哪个表,因为列出现在多个表中,所以尝试在列之前使用表名
mshiptypes.mshipType_Name
在您使用OR时,mshipStatusType_Name中不可能存在两个值 而不是像这样:
mshipStatusType_Name='value1' or mshipStatusType_Name='value2' ....
答案 1 :(得分:0)
即使已经评论过,我也会发布一个答案。该错误源于您的where
正在执行的表格不包含mshipStausType_Name
列。如评论,并查看您的SQL,有一个mshipStatusType_Name
的引用,所以我也假设拼写错误。