Hi everyone,
I am trying to find all the values in one column of a table that do not appear in another column of the same table.
On my local machine running mysql v5 the following does nicely;-
Unfortunately the development environment (unlike anywhere else in the whole place) is running mysql v4.1 where sub queries dont work.
So... i have put this together to try and acheive the same thing;-
This is giving me a Cartesian product i.e. thousands of results, whereas i get about 300 from the v5 query.
Any suggestions welcome.
Thanks
I am trying to find all the values in one column of a table that do not appear in another column of the same table.
On my local machine running mysql v5 the following does nicely;-
Code:
SELECT cat.id, cat.parentid FROM categories cat WHERE cat.id NOT IN (SELECT distinct parentid FROM categories);
Unfortunately the development environment (unlike anywhere else in the whole place) is running mysql v4.1 where sub queries dont work.
So... i have put this together to try and acheive the same thing;-
Code:
SELECT cat.id, cat.parentid
FROM categories cat
LEFT JOIN (
SELECT DISTINCT (cat2.parentid) AS cat2parentid FROM
categories cat2
) as uniParent
ON cat.id not in (uniParent.cat2parentid);
This is giving me a Cartesian product i.e. thousands of results, whereas i get about 300 from the v5 query.
Any suggestions welcome.
Thanks