Я пишу этот запрос для извлечения данных из 3 разных таблиц.
Здесь [все выбранные мной столбцы взяты из первой и второй таблицы], данные извлекаются так, как мне действительно нужно:
SELECT DISTINCT SD.salary_component,SS.posting_date,SS.payroll_entry,
SD.parentfield,SD.amount,SS.employee,SS.name
FROM`tabSalary Detail` SD
INNER JOIN `tabSalary Slip` SS
ON SS.name=SD.parent
INNER JOIN `tabGL Entry` GL
ON GL.against_voucher=SS.payroll_entry
WHERE SS.employee='EMP0110' AND
SS.posting_date='2020-03-11' AND
SD.parentfield != 'indebtedness' AND
SS.payroll_entry='HR-PRUN-2019-01027';
желаемый результат и результат запроса
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04
=======
Но, когда я выбрал два столбца в третьей таблице, что-то идет не так, и данные продублировано:
SELECT DISTINCT SD.salary_component,SS.posting_date,SS.payroll_entry,
SD.parentfield,SD.amount,SS.employee,SS.name
GL.credit,GL.debit
FROM`tabSalary Detail` SD
INNER JOIN `tabSalary Slip` SS
ON SS.name=SD.parent
INNER JOIN `tabGL Entry` GL
ON GL.against_voucher=SS.payroll_entry
WHERE SS.employee='EMP0110' AND
SS.posting_date='2020-03-11' AND
SD.parentfield != 'indebtedness' AND
SS.payroll_entry='HR-PRUN-2019-01027';
второй результат запроса - 54 дублированных строки
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 300.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 300.000000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 500.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 500.000000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 3600.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 3600.000000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 445.890000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 445.890000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 336.990000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 336.990000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 95.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 95.000000 0.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 1150.000000
AAAA 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 1150.000000 0.000000
===================================================================================================================================
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 300.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 300.000000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 500.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 500.000000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 3600.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 3600.000000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 445.890000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 445.890000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 336.990000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 336.990000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 95.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 95.000000 0.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 1150.000000
BBBB 2020-03-11 HR-PRUN-2019-01027 earnings 300.000000 EMP0110 Sal Slip-EMP0110-1911-04 1150.000000 0.000000
===================================================================================================================================
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 300.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 300.000000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 500.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 500.000000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 3600.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 3600.000000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 445.890000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 445.890000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 336.990000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 336.990000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 95.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 95.000000 0.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 1150.000000
CCCC 2020-03-11 HR-PRUN-2019-01027 earnings 500.000000 EMP0110 Sal Slip-EMP0110-1911-04 1150.000000 0.000000
===================================================================================================================================
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 300.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 300.000000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 500.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 500.000000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 3600.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 3600.000000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 445.890000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 445.890000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 336.990000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 336.990000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 95.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 95.000000 0.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 0.000000 1150.000000
DDDD 2020-03-11 HR-PRUN-2019-01027 earnings 3600.000000 EMP0110 Sal Slip-EMP0110-1911-04 1150.000000 0.000000
что не так и какие темы мне следует искать, чтобы получить идею? наконец, что является лучшим решением?