ВЫБЕРИТЕ из 2 таблиц - PullRequest
2 голосов
/ 12 февраля 2011

Мои таблицы:

table1

id|name_transfer|id_account_from|value_from|id_account_to|value_to
------------------------------------------------------------------
1 |transfer1    |1              |1000      |2            |1000

table2

id|name_account|
----------------
1 |account1    |
2 |account2    |

Как написать запрос, который я дал так:

transfer1|account1|1000|account2|1000

1 Ответ

5 голосов
/ 12 февраля 2011
select
  t1.name_transfer, 
  t2a.name_account as name_account_from, 
  t1.value_from, 
  t2b.name_account as  name_account_to, 
  t1.value_to
from
  table1 t1
  inner join table2 t2a on t2a.id = t1.id_account_from
  inner join table2 t2b on t2b.id = t1.id_account_to
where
  t1.id = 1
...