Reputation: 119
SQL> desc airport
Name Null? Type
----------------------------------------- -------- ----------------------------
AIRPORT_ID NOT NULL NUMBER(5)
CITY_ID NOT NULL NUMBER(5)
AIRPORT VARCHAR2(59)
IATA_CODE VARCHAR2(3)
SQL> desc city
Name Null? Type
----------------------------------------- -------- ----------------------------
CITY_ID NOT NULL NUMBER(5)
COUNTRY_ID NOT NULL NUMBER(5)
CITY VARCHAR2(36)
SQL> desc country
Name Null? Type
----------------------------------------- -------- ----------------------------
COUNTRY_ID NOT NULL NUMBER(5)
COUNTRY VARCHAR2(36)
Here is the query:
select airport_id, airport, iata_code, city, country
from airport a, city b, country c
where a.city_id = b.city_id
and b.country_id = c.country_id
and b.city like '%tehran%' or iata_code like '%tehran%'
order by airport asc;
This query is not responding or talking minutes to respond whilst when I ran same query with one parameter like and b.city like '%tehran%'
by removing or iata_code like '%tehran%'
then its running fine and results in less than a second
why its not responding with two parameters e.g. and b.city like '%tehran%' or iata_code like '%tehran%'
Upvotes: 0
Views: 102
Reputation: 22811
Looks like you want
select airport_id, airport, iata_code, city, country
from airport a
join city b on a.city_id=b.city_id and (b.city like '%tehran%' or b.iata_code like '%tehran%')
join country c on b.country_id=c.country_id
order by airport asc;
Note SQL standard JOIN syntax and the order of logical AND/OR operations fixed using brackets.
Upvotes: 2