Hi I do not know a whole lot about SQL this is definitely one of my weak points. this is an Oracle DB.

I have 2 tables:

```
TAXI_ROUTES_TABLE:
ID  | ORIGIN   | DESTINATION | TAXI_NUMBER |  STOPS   | DAY_OF_OPERATION | INSERT_DATE
123  NORTH AVE   CAMPBELL      1552          1W;2T;4Y   01-FEB-20          27-DEC-19
124  LEMMON AVE  HENRY ST      1511          1R;5G;P3   02-FEB-20          25-DEC-19

```

---

```
TAXI_FARE_TABLE:
ID  | ORIGIN   | DESTINATION | TAXI_NUMBER |  STOPS   |  FARE_TYPE | FARE_TYPE_AVAIL 
123  NORTH AVE   CAMPBELL      1552          1W;2T;4Y      SENIOR        5             
123  NORTH AVE   CAMPBELL      1552          1W;2T;4Y      STUDENT       10            
123  NORTH AVE   CAMPBELL      1552          1W;2T;4Y      EMPLOYEE      10            
124  LEMMON AVE  HENRY ST      1511          1R;5G;P3      SENIOR        5             
124  LEMMON AVE  HENRY ST      1511          1R;5G;P3      STUDENT       3             
124  LEMMON AVE  HENRY ST      1511          1R;5G;P3      EMPLOYEE      10  

```

**TAXI\_ROUTES\_TABLE INDEX:** 

```
STOPS, TAXI_NUMBER, DESTINATION, ORIGIN, DAY_OF_OPERATION

CREATE INDEX "TAXI_ADMIN"."IX01_TAXI_ROUTES_TABLE" ON 
"TAXI_ADMIN"."TAXI_ROUTES_TABLE" ("STOPS", "TAXI_NUMBER", "DESTINATION", 
"ORIGIN", "DAY_OF_OPERATION ") 
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "TAXI_ADMIN" ; 

```

**TAXI\_FARE\_TABLE** does not have any indexes.

**These tables have millions of records in them**. the same records are in both tables its just that the taxi fare table has them repeated due to the types of fares for each taxi. 

so I am trying to do a join to be able to get all the **most recently inserted** records and the fare types for them. So I should only get back the records inserted on 27-DEC-19. 

**My problem:** my query is maxing out the time limit, its taking forever. I would really appreciate your guidance on this.

**SQL:** 

```
SELECT R.ID,
       R.ORIGIN,
       R.DESTINATION,
       R.TAXI_NUMBER,
       R.STOPS,
       R.DAY_OF_OPERATION,
       R.INSERT_DATE,
       F.FARE_TYPE,
       F.FARE_TYPE_AVAIL
FROM TAXI_ADMIN.TAXI_ROUTES_TABLE R, TAXI_ADMIN.TAXI_FARE_TABLET F

WHERE INSERT_DATE = (SELECT MAX(INSERT_DATE) FROM TAXI_ADMIN.TAXI_ROUTES_TABLE)

AND R.ID = F.ID

ORDER BY R.ORIGIN, R.DESTINATION, R.DAY_OF_OPERATION;

```

I am not sure how can I make the query faster. When I run without the order by its pretty quick but the order by takes a really long time. 

thank you