Таблицы
Есть таблица projects.
-----------------------------
| project_id | project_title |
-------------|----------------
| 154 | Ярославль |
-------------|----------------
| 278 | Москва |
-------------|----------------
| 322 | СПб |
------------------------------
Есть вторая таблица orders
----------------------------------------
| order_id | order_from | order_to |
----------------------------------------
| 1 | 278 | 322 |
----------------------------------------
| 2 | 154 | 322 |
----------------------------------------
| 3 | 278 | 154 |
----------------------------------------
Нужно сопоставить order_from and order_to с таблицей projects, вывести project_title, где order_from = project_id and order_to=project_id
т.е. на выходе
------------------------------------------
| Заказ | ИЗ | В |
------------------------------------------
| 1 | Москва | СПБ |
------------------------------------------
| 2 | Ярославль | СПБ |
------------------------------------------
| 3 | Москва | Ярославль |
-------------------------------------------
SELECT * FROM `orders` AS OR
JOIN `projects` AS PR ON PR .project_id=`OR `.order_from AS itsfrom
AND
JOIN `projects` AS PR ON PR .project_id=`OR `.order_to AS itsto