select t1.id, t1.city_name,t1.external_code, t3.county_name, t3.external_code, t3.region_id --,t4.region_name, t4.external_code
from t_city t1
join t_city_rus t2 on t1.id = t2.id
join t_county t3 on t1.county_id = t3.id
join t_region t4 on t3.region_id = t4.id
where developer_desc like '%TEST%INS%';
This code returns NULL though all joins look good and all connections were made correctly. The reason of getting nothing is absence of prefix for field in the filter. When you forget to write a table prefix for a field in condition WHERE, Oracle tries to find the field in the last table used in a query (by default). So if it finds such a field, it tries to match it, otherwise we get an error. In this case, Oracle has found the field and tried to match, however, there is no match in the last table field, so it returns NULL.
So we know that we need field of the third table, then working code is:
select t1.id, t1.city_name,t1.external_code, t3.county_name, t3.external_code, t3.region_id --,t4.region_name, t4.external_code
from t_city t1
join t_city_rus t2 on t1.id = t2.id
join t_county t3 on t1.county_id = t3.id
join t_region t4 on t3.region_id = t4.id
where t3.developer_desc like '%TEST%INS%';
You are viewing
itsepainen's journal