sql查询连接多个表
我想从人员和地址中获取CategoryId等于category的所有列 我有这个疑问sql查询连接多个表,sql,Sql,我想从人员和地址中获取CategoryId等于category的所有列 我有这个疑问 SELECT Category.Id, People.*, Adress.* FROM Category JOIN People ON People.CategoryId = Category.CategoryId JOIN Adress ON Adress.PeopleId = People.Id WHERE Categor
SELECT
Category.Id, People.*, Adress.*
FROM
Category
JOIN
People ON People.CategoryId = Category.CategoryId
JOIN
Adress ON Adress.PeopleId = People.Id
WHERE
Category.CategoryId = @category
ORDER BY
People.PeopleId DESC ;
运行应用程序时出现错误
“/”应用程序中出现服务器错误
列名“Id”无效。列名“Id”无效
描述:在执行过程中发生未处理的异常
当前的web请求。请查看堆栈跟踪以了解更多信息
有关错误的信息及其在代码中的来源
异常详细信息:System.Data.SqlClient.SqlException:无效列
名称“Id”。列名“Id”无效
源错误:第153行:da.SelectCommand=command;线
154:DataTable dt=新DataTable();第155行:da.填充(dt);第156行:cn.Close();第157行:
PagedDataSource pgitems=新的PagedDataSource() 为什么它不起作用?要帮忙吗
使用VisualStudio本地数据库 错误是因为表“Category”没有列名“Id”。看起来您需要将其更改为“CategoryId”
您的人员表(无“Id”列)也可能存在类似问题。错误似乎在Category.Id上,请验证此大写字母是否正确。我认为这类似于“Category.id”或“Category.CategoryId”将id更改为各自的CategoryId和PeopleId
SELECT Category.CategoryId , People.*, Adress.*
FROM Category JOIN People ON People.CategoryId=Category.CategoryId
JOIN Adress ON Adress.PeopleId=People.PeopleId
WHERE Category.CategoryId=@category
ORDER BY People.PeopleId DESC ;
什么不起作用?它在语法上不正确吗?你得到了意想不到的结果吗?请澄清运行时会发生什么?这是用于哪个RDBMS的?请添加一个标记,以指定您是在使用
mysql
、postgresql
、sql server
、oracle
还是db2
——还是完全其他什么。我更新了我的帖子。对不起,伙计们。类别有一个名为CategoryId的列。对吧——那么为什么在代码中引用“Category.Id”?谢谢你们的帮助。我对约束键也有问题。但现在它工作得很好:))