Select Column value based on two values in another column
If I understand, you want to get all trip_id values that appear in the table, against one stop_id on one or more rows, and against another stop_id on other rows. This should do it:

select trip_id 
from stop_times 
where stop_id = 1538 
or stop_id = 1540
group by trip_id
having count(distinct stop_id) &gt; 1;


Example: http://sqlfiddle.com/#!9/e78aa/1

Notice that trip_id 0051ML66220600132483 matches on one stop but not the other, so is not returned.