我正在使用访问,我有两个表:
观点:
id,x,y
1 32432432 143423232
2 32432443 143423300
线:
id startPoint endPoint
1 1 2
现在,当我查询该行时,我希望返回的表将同时包含 startPoint 和 endPoint 的 x、y。
我试过加入:
select line.*,point.x as x1,point.y as y1 from line as line join point as point on line.startPoint=point.id where line.id=1;
然后我可以得到以下仅包含 startPoint 的结果。
id startPoint endPoint x1 y1
1 1 2 ......
那么当我想要这样的结果时如何检索endPoint(x2 y2是endPoint的坐标):
id startPoint endPoint x1 y1 x2 y2
1 1 2 ......
我尝试了两个join
,但它不起作用。
select line.*,point1.x as x1,point1.y as y1,point2.x as x2,point.y as y2 from line as line left join point1 as point on line.startPoint=point1.id left join point as point2 on line.endPoint=point2.id where line.id=1;