我在 Oracle 数据库中有两个表(10g 快递)
- 产品
- 产品图片
一个产品可以有多个图像。product
因此,从to存在一对多关系,product_image
并且product_image
表具有引用product
表的主键的外键。
我需要获取一个产品列表,在检索的结果集的每一行中只有一个图像名称,而不管product_image
表中的图像如何(即使某些产品没有图像)。
从product_image
表中取到的图片名称一般是对每个产品product_image
的每组图片进行升序排序后的表中的第一个图片名称。类似于以下内容。
prod_id prod_name prod_image
1 aaa aaa.jpg //The first image name in the product_image table after sorting images for prod_id in ascending order.
2 bbb bbb.jpg //Similar to the first case.
3 ccc - //No image(s) found in the product_image table
4 ddd - //Similar to the previous case.
这两个表的一般连接语句类似于以下内容。
SELECT p.prod_id, p.prod_name, pi.prod_image
FROM product p
INNER JOIN product_image pi
ON p.prod_id=pi.prod_id;
这可能使用单个 SQL 语句吗?