嗨,我想做一个好的查询以获得一个好的数组。现在例如我有这个查询:
SELECT DISTINCT * FROM products
LEFT OUTER JOIN product_aliases
ON product_aliases.product_id = products.id
AND product_aliases.alias = '$alias'
LEFT OUTER JOIN (product_images
LEFT OUTER JOIN product_image_votes
ON product_image_votes.product_image_id = product_images.id)
ON product_images.product_id = products.id
WHERE products.id = $id
结果是两个这样的数组:
array(
(int) 0 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
),
'product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
)
),
(int) 1 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
),
'product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
)
)
问题是:我只想要一个包含产品的唯一数组,例如包含在数组 product_images_votes 中的 product_images。第一个问题是:
- 有一个唯一的数组而不是两个数组
- 在我的左连接 annidate 的基础上创建数组内的数组
数组示例:
array(
(int) 0 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
array('product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
))
)
有可能吗?我正在使用 php