I have a problem with my SQL query. I am trying to query the database to get data from 3 different tables, where on one table conditions are applied. On the second entry it shows the results correctly, though on the first it lacks to show the results of the table where the conditions are applied.
This is my query:
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`
This is what it returns:
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
)
)
I think it has something to do with the limit specified on the LEFT JOIN query, but I'm not sure about that. I don't know how else to query the database to get these results.
Thanks in advance (: