Во-первых, у меня есть две таблицы, и я делаю соединение с помощью следующего запроса
ВЫБЕРИТЕ o5.id AS id, DATE_FORMAT (o5.vreme_isplata, '% d.% M.% Y') AS payed_date, o5.ime_prezime AS имя, o5.adresa AS адрес, o5.mesto AS city, o5.embg AS mb, o5.serial_no AS билет, о1.уплата А.С. уплата, o5.pdd AS danok, о5.исплата А.С. нетідобивка, о1.износ_исплатен А.С. бруто_добовка ОТ о5 ВНУТРЕННИЙ РЕЙТИНГ o1 ON o5.serial_no = o1.serial_no ГДЕ o1.transaction_type = 'I'
и его работа отлично
Теперь мне нужно выбрать данные из другой таблицы «o1_payout_storno», которая совпадает с o1
Мне нужно выбрать данные из o5
а также INNER JOIN
UNION ALL
выбор из o1
а также o1_payout_storno
,
Это должно быть просто так:
SELECT
o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
o1.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
o1.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1 ON o5.serial_no = o1.serial_no
WHERE o1.transaction_type = 'I'
UNION ALL
SELECT
o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
op.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
op.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1_payout_storno AS op ON op.serial_no = o5.serial_no
Наконец я получил запрос
SELECT o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
o1.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
o1.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1 ON o5.serial_no = o1.serial_no
WHERE o1.transaction_type = 'I'
UNION ALL
SELECT o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
o1_payout_storno.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
o1_payout_storno.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1_payout_storno ON o5.serial_no = o1_payout_storno.serial_no
WHERE o1_payout_storno.transaction_type = 'I'
ORDER BY payed_date ASC
Это работает, как я ожидал!