数据库同时查询多个表
我在同一个数据库下建立了三个表:
1,表:project
projectId | projectName |
2,表:position
positionId | positionName |
3,表:work
workId |
workprojectId |
workpositionId |
workAmount |
workTime |
workStatus |
testTime |
int |
int |
int |
int |
datetime |
binary |
int |
而projectId和position都是work的外键,对应:workprojectId和workpositionId,要取得如下数据:
projectName, positionName, workAmount,workTime, workStatus, testTime则是如下sql语句(想了老半天,后来在
SQLExpress下查询成功)
SELECT project.projectName, position.positionName, [work].workAmount, [work].workTime,
[work].workStatus, [work].testTime
FROM position INNER JOIN
[work] ON position.positionId = [work].workposition INNER JOIN
project ON [work].workprojectId = project.projectId
努力不一定成功,但放弃一定失败!