I am trying to make a query for that contains left outer join and a query that contains a sub query. I tried the following code:
select c.CustomerName,l.Way,l.Travel
from (select l.HomeAdd from tbl_Location l
where l.HomeAdd like '%Colombo%') from
tbl_Customer c left outer join tbl_Location l
on (l.location_id=c.location_id);
I get the following error message
tbl_Customer c left outer join tbl_Location l
*
ERROR at line 4:
ORA-00933: SQL command not properly ended
Please help!!!
Very strange query. I assume you intend:
select c.CustomerName, l.Way, l.Travel
from tbl_Customer c left outer join
tbl_Location l
on l.location_id = c.location_id and l.HomeAdd like 'Colombo%';
The problem with your query is you have subquery in the where
clause. There is no comparison -- not =
, no exists
, no in
, nothing that represents a boolean expression.
It looks like you are missing EXISTS keyword in the query
select c.CustomerName,l.Way,l.Travel
from tbl_Customer c left outer join tbl_Location l
on (l.location_id=c.location_id)
where EXISTS (
select l.HomeAdd from tbl_Location l
where l.HomeAdd like 'Colombo%'
);
If you insist upon using a subquery I suggest you do something like:
select c.CustomerName,
l.Way,
l.Travel
from tbl_Customer c
left outer join (SELECT l.HOMEADD,
l.WAY,
l.TRAVEL
FROM tbl_Location
WHERE l.HOMEADD LIKE 'Colombo%') l
on l.location_id=c.location_id
Also, a comment: I strongly suggest that you should not prefix the names of tables etc, with something like 'TBL_'. When tables, etc, are used the context of the usage tells you what the object is. Oracle identifiers are limited to 30 characters - IMO sacrificing 13% of the available name length to a prefix is simply wasteful.
Best of luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.