对mysql表中主键的多次引用
我试图通过引用多个表中的主键来检索值,但无法获取结果。这是表
Density Table
**de_id density color**
1 21 red
2 22 blue
3 23 green
4 24 yellow
5 25 orange
Size Table
**si_id length breadth**
1 21 41
2 22 42
3 23 43
4 24 44
5 25 45
Order_de Table
**or_id density color length breadth**
1 1 2 3 4
2 4 3 2 1
我试图计算出的查询是
SELECT density.density,density.color,size.length,size.breadth,order_de.or_id from
density,size,order_de WHERE order_de.density=density.de_id and
order_de.color=density.de_id and order_de.length=size.si_id and
order_de.breadth=size.si_id order by order_de.or_id asc
期望的结果应该是
density color length breadth or_id
21 blue 23 44 1
24 green 22 41 2
但查询什么也检索不到。 任何人都可以帮忙吗?
i trying to retrieve value by referencing primary key in multiple tables but unable to get the result.Here is the table
Density Table
**de_id density color**
1 21 red
2 22 blue
3 23 green
4 24 yellow
5 25 orange
Size Table
**si_id length breadth**
1 21 41
2 22 42
3 23 43
4 24 44
5 25 45
Order_de Table
**or_id density color length breadth**
1 1 2 3 4
2 4 3 2 1
The query i am trying to work out is
SELECT density.density,density.color,size.length,size.breadth,order_de.or_id from
density,size,order_de WHERE order_de.density=density.de_id and
order_de.color=density.de_id and order_de.length=size.si_id and
order_de.breadth=size.si_id order by order_de.or_id asc
The desired result should be
density color length breadth or_id
21 blue 23 44 1
24 green 22 41 2
But the query retrieves nothing.
Can any one help??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为每个属性独立连接到表:密度、颜色、长度和宽度。另外,不要使用隐式连接样式。我认为这导致您在生成此查询时感到困惑。
You need to join to the tables independently for each attribute: density, color, length and breadth. Also, don't use the implicit join style. I think that contributed to your confusion in producing this query.