> For the complete documentation index, see [llms.txt](https://lei-d.gitbook.io/sql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lei-d.gitbook.io/sql/sqlzoo/self-join-edinburgh-buses-data.md).

# Edinburgh Buses data

## 10

Find the routes involving two buses that can go from Craiglockhart to Sighthill. Show the bus no. and company for the first bus, the name of the stop for the transfer, and the bus no. and company for the second bus.

```php
SELECT DISTINCT 
        r1.num, 
        r1.company, 
        (SELECT name FROM stops WHERE id = r2.stop) AS name, 
        r4.num, 
        r4.company
FROM route AS r1 
        JOIN route AS r2 ON (r1.num = r2.num AND r1.company = r2.company AND r1.stop != r2.stop)
        JOIN route AS r3 ON (r2.stop = r3.stop)
        JOIN route AS r4 ON (r3.num = r4.num AND r3.company = r4.company)
WHERE 
        r1.stop = (SELECT id FROM stops WHERE name = 'Craiglockhart') 
        AND r4.stop = (SELECT id FROM stops WHERE name = 'Sighthill') ;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lei-d.gitbook.io/sql/sqlzoo/self-join-edinburgh-buses-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
