I'm joinning two SELECTS. The first one retrieves:
t1
id value
1 149
2 149
3 149
4 149
The second one:
t2
id value
149 2
149 13
149 145
149 149
So, I'm joining t1/t2 on t1.value = t2.id
. But the outcome follows:
1 149 2
1 149 13
1 149 145
1 149 149
2 149 2
2 149 13
2 149 145
2 149 149
3 149 2
3 149 13
3 149 145
3 149 149
4 149 2
4 149 13
4 149 145
4 149 149
When the desired result should look like this:
1 149 2
2 149 13
3 149 145
4 149 149
I think that the problem appears because this are SELECT and not tables. After googling a lot I couldn't find any solution.
EDIT: MySQL query:
SELECT t1.id_sequence,t2.id_category, t2.tree
FROM
(
SELECT * FROM (SELECT 1 AS id_sequence UNION SELECT 2 AS id_sequence UNION SELECT 3 AS id_sequence UNION SELECT 4 AS id_sequence ) as tbl1
CROSS JOIN (SELECT DISTINCT id_catalog_category AS 'id_category' from catalog_category where id_catalog_category = 149) as tbl2
) as t1
LEFT JOIN
(
SELECT child.id_catalog_category AS id_category, ancestor.id_catalog_category AS tree
FROM catalog_category AS child
JOIN catalog_category AS ancestor
ON (child.lft BETWEEN ancestor.lft AND ancestor.rgt)
WHERE child.id_catalog_category = 149 AND ancestor.id_catalog_category != 1
) as t2
ON t1.id_category = t2.id_category
Select retrieved table1 and table2 respectively.