Hello, below is my rather complecated sql query. It does two things:
a) Gets all the articles in catagory '4'
b) Gets all the articles in catagories with parent catagory '4'
(a) and (b) run fine on their own, but when i combine them with an OR statement, i get multiple (seemingly) redundant results. Only one of which has the desired catagory information. If i use "GROUP BY a.`id`" I get the right results, but not the right catagory information for (b).
Appologies if this is uninteligible!!! I could provide a database dump if it would help?
Query below:
Thanks,
James
a) Gets all the articles in catagory '4'
b) Gets all the articles in catagories with parent catagory '4'
(a) and (b) run fine on their own, but when i combine them with an OR statement, i get multiple (seemingly) redundant results. Only one of which has the desired catagory information. If i use "GROUP BY a.`id`" I get the right results, but not the right catagory information for (b).
Appologies if this is uninteligible!!! I could provide a database dump if it would help?
Query below:
Thanks,
James
Code:
SELECT a.* , a_c.`catagory`
FROM
`articles` AS a, `article_catagories` AS a_c, `catagories` AS c
WHERE (
a_c.`catagory` =4
OR (
c.`id` = a_c.`catagory`
AND c.`parent` =4
)
)
AND a.`id` = a_c.`article`