简体   繁体   English

SQL查询一对多

[英]SQL query one-to-many

I need SQL query for the below scenario.我需要以下场景的 SQL 查询。

2 tables: price & product 2 表:价格和产品

price table has ManyToOne relationship with product(ie, many prices were applicable to one product).价格表与产品具有多对一关系(即,多个价格适用于一种产品)。

Now I need a query to get only the product details which available in price table.现在我需要查询以仅获取价格表中可用的产品详细信息。

Note: Using hibernate, I have specified in price as注意:使用休眠,我已将价格指定为

@ManyToOne @JoinColumn(name = "PRODUCT_ID") private Product product; @ManyToOne @JoinColumn(name = "PRODUCT_ID") 私有产品;

But I don't specify OneToMany in product.但我没有在产品中指定 OneToMany。

In this case you can return the product attribute in your query, example:在这种情况下,您可以在查询中返回产品属性,例如:

select p.product from price p where p = :price

Hope this can help.希望这能有所帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM