I am trying to select columns from different tables and create a new table, for example "test". if the inputs from the "Operador" and "Data" column inserted in the tables: "Busy", "Login" can't locate the inputs of the same columns from the "Atendidas" table then it displays NULL. It is probably simple but i can't really get there.
What i want is the following example:
Table Atendidas:
ID Ano Mes Data Operador Atendidas
1 2020 JANEIRO 2020 2020/01/01 CCTLT413 30
2 2020 JANEIRO 2020 2020/01/01 CCVTH2498 31
3 2020 JANEIRO 2020 2020/01/01 XKELB80 27
4 2020 JANEIRO 2020 2020/01/01 XKELI28 29
5 2020 JANEIRO 2020 2020/01/01 XKELN94 24
Table Busy:
ID Ano Mes Data Operador Busy
1 2020 JANEIRO 2020 2020/01/01 CCTLT413 6812
2 2020 JANEIRO 2020 2020/01/01 CCTL200 3245
3 2020 JANEIRO 2020 2020/01/01 XKELB80 12305
4 2020 JANEIRO 2020 2020/01/01 XKELI28 7764
5 2020 JANEIRO 2020 2020/01/01 XKELN94 6014
Table Login:
ID Ano Mes Data Operador Login
1 2020 JANEIRO 2020 2020/01/01 CCTLT413 19475
2 2020 JANEIRO 2020 2020/01/01 CCVTH2498 20209
3 2020 JANEIRO 2020 2020/01/01 XKELB80 21625
4 2020 JANEIRO 2020 2020/01/01 XKELI28 21175
5 2020 JANEIRO 2020 2020/01/01 XKV220 22121
test:
ID Data Operador Atendidas Busy Login
1 2020/01/01 CCTLT413 30 6812 19475
2 2020/01/01 CCVTH2498 31 *NULL* 20209
3 2020/01/01 XKELB80 27 12305 21625
4 2020/01/01 XKELI28 29 7764 21175
5 2020/01/01 XKELN94 24 6014 *NULL*
Solution:
This worked, i have to Left join the data which i was not doing it.:
SELECT A.Data, A.Operador, A.Atendidas, B.Busy, B.Login
from Atendidas as A
left join [Busy] as B on B.Operador = A.Operador
and B.Data = A.Data
left join [Login] as L on L.Operador = A.Operador
and L.Data = A.Data;