我的 SQL 查询有问题。我正在尝试查询数据库以从 3 个不同的表中获取数据,其中应用了一个表条件。在第二个条目上,它正确显示了结果,但在第一个条目上,它没有显示应用条件的表格的结果。
这是我的查询:
SELECT
`".PRODUCTS."`.*,
`".CATEGORIES."`.*,
`q_prices`.*
FROM
`".PRODUCTS."`
LEFT JOIN
`".CATEGORIES."`
ON
`".PRODUCTS."`.`category_id` = `".CATEGORIES."`.`category_id`
INNER JOIN(
SELECT
`".PRICES."`.*
MAX(`".PRICES."`.`price_modified`) modified
FROM
`".PRICES."`
GROUP BY
`".PRICES."`.`product_id`
) `q_prices`
ON
`".PRODUCTS."`.`product_id` = `q_prices`.`product_id`
这是它返回的内容:
Array
(
[0] => stdClass Object
(
[product_id] => 1
[product_name] => Test product
[product_alias] => test-product
[category_id] => 1
[product_created] => 2013-07-29 11:36:51
[product_modified] => 2013-07-29 11:36:51
[category_name] => Test categorie
[category_alias] => test-categorie
[category_parent] => wonenplaza.nl
[category_created] => 2013-07-29 11:39:29
[category_modified] => 2013-07-29 11:39:29
[price_id] => 1
[price_amount] => 25.00
[price_tax] => 21
[price_created] => 2013-07-29 11:38:18
[price_modified] => 2013-07-29 11:38:18
[modified] => 2013-07-29 11:38:52
)
[1] => stdClass Object
(
[product_id] => 2
[product_name] => Priva Blue ID
[product_alias] => test-product2
[category_id] => 1
[product_created] => 2013-07-29 12:18:54
[product_modified] => 2013-07-29 12:18:54
[category_name] => Test categorie
[category_alias] => test-categorie
[category_parent] => wonenplaza.nl
[category_created] => 2013-07-29 11:39:29
[category_modified] => 2013-07-29 11:39:29
[price_id] => 4
[price_amount] => 20.00
[price_tax] => 21
[price_created] => 2013-07-29 12:19:11
[price_modified] => 2013-07-29 12:19:11
[modified] => 2013-07-29 13:30:05
)
)
我认为这与 LEFT JOIN 查询中指定的限制有关,但我不确定。我不知道如何查询数据库以获得这些结果。
提前致谢 (: