I have following query:
SELECT * FROM
(
SELECT
catalog.*,
images.image
FROM `catalog` as catalog
INNER JOIN `type5` as images ON catalog.id = images.id
WHERE catalog.left_key > (SELECT `left_key` FROM `catalog` WHERE `id`=235) AND catalog.right_key < (SELECT `right_key` FROM `catalog` WHERE `id`=235)
ORDER BY catalog.left_key ASC
) ilv
This query works well, but it SELECTS only items FROM catalog only if in table type5 is same item id.
For example in in catalog I have:
id name
5 Hello
7 World
8 Foo
9 Bar
And in type 5 I have:
id image
5 hello.png
8 foo.png
9 bar.png
It will selects only
5 Hello
8 Foo
9 Bar
How to edit my query to select items from catalog even if there is no same id in type5?
You’re using an
inner join, which means it will only get the items which are in both tables.You’re probably looking for a
left outer join.If you don’t really get how joins work, here is a good visual representation which explains it.