i have 3 rows on “Services” table:
ID | name | ObrID
0 | A | 1
1 | B | 2
2 | C | -1
-1 is a none existing Obr, the service 2 doesn’t contains any Obr or it was deleted.
if i fetch with select * from Services, it works as expected, but if i do my search sql:
select
*,
(select Name from Obrs where ID=ObrID) as ObrName
from
Services
where
(select Name from Obrs where ID=ObrID) like '%SEARCH_STRING%'
it doesn’t return the last line. Is there any way so it return something like:
ID | name | ObrID | ObrName
0 | A | 1 | ObrA
1 | B | 2 | ObrB
3 | C | -1 | NULL
You want to use left join.
http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php
or: