2
Good morning!
I’m trying to make a script where doing 2 joins, it shows me 3 columns.
I mean, what I want is to get the email do lider
. However it does not have a specific column, it is inserted your email in the column Email Lider
, and there are also the emails do gestores
.
Should appear this way:
ID | Email Gestor | Email Lider
-------------------------------
13 | [email protected] | [email protected]
14 | [email protected] | [email protected]
15 | [email protected] | [email protected]
16 | [email protected] | [email protected]
17 | [email protected] | [email protected]
18 | [email protected] | [email protected]
The problem is I’m not finding the right code for it. And so the result I get is this:
ID | Email Gestor | Email Lider
-------------------------------
13 | [email protected] | [email protected]
14 | [email protected] | [email protected]
15 | [email protected] | [email protected]
16 | [email protected] | [email protected]
17 | [email protected] | [email protected]
18 | [email protected] | [email protected]
That is, instead of getting the mails from leaders, I get emails from managers.
The table to find the name of the leaders is basically like this:
-- Tabelas que estou a fazer consulta:
-- Tabela Tecnicos S --
IDGestor | NomeGestor | Email
----------------------------------------
13 | pd | [email protected] |
14 | pf | [email protected] |
15 | fp | [email protected] |
16 | fd | [email protected] |
17 | ff | [email protected] |
18 | gg | [email protected] |
19 | lider | [email protected] |
20 | lider2 | [email protected] |
-- Tabela Reclamaçoes R --
IDGestor | Resolvido |
-----------------------
13 | 0 |
14 | 0 |
15 | 0 |
16 | 0 |
17 | 0 |
18 | 0 |
19 | 0 |
20 | 0 |
-- Tabela Vendedor S --
IDGestor | NomeGestor |
------------------------
13 | pd |
14 | pf |
15 | fp |
16 | fd |
17 | ff |
18 | gg |
19 | lider |
20 | lider2 |
That is, the columns link to each other: Complaints with Seller: Manager Id Technical Complaints : Manager Id Seller with Technique : Manager Id and Manager Name
The code I have is this:
SELECT R.ID
,VS.Email AS EmailGestor
,TS.email AS EmailLider
FROM dbo.Reclamacoes R
INNER JOIN dbo.TECNICOS_S TS ON R.IdGestor = TS.IdTecnico
INNER JOIN dbo.VENDEDORES_S VS ON R.IdGestor = VS.IdVendedor
WHERE R.Resolvido = 0
ORDER BY R.ID
Can anyone help me? Any doubt to understand what I want to know, don’t hesitate to ask. Thanks in advance.
How do you know the difference between manager and leader? Edit your question and put the table structure you are using in the query.
– João Martins
@Joãomartins has already been changed, can you understand that? The difference between the manager is that the manager has the name "pf" for example, only 2 letters. the leader even has the name "lider" for example.
– Miguel Meireles
If you’re connecting the table
Reclamacoes
by the columnIdGestor
at the tableTECNICOS_S
by the columnIdTecnico
(that in the structure that placed I imagine that corresponds toIDGestor
) then you won’t be able to get the leader’s email, because you’re associating with the ID, which always brings you the email associated with that ID, and not any other associated with a leader.– João Martins
@Joãomartins then how do I get this email?
– Miguel Meireles
Then you have to create a column that associates the manager to a leader.
– João Martins
create a column or select? the database is from the company where I am interning, I cannot and do not have permissions to create columns in the tables.
– Miguel Meireles
With this structure I see no way to get the result you want :/
– João Martins
@Joãomartins what can I do for you to understand and help me? I really need to finish this as soon as possible
– Miguel Meireles
Let’s go continue this discussion in chat.
– João Martins