Difference between select a. or b

Asked

Viewed 236 times

4

What’s the difference of doing the search by select a. or b.?

Example:

select --a.num_duplicata,a.data_prorrogacao,a.seq_duplicatas,
        a.cli_dup_cgc_cli9 as cgc9,a.cli_dup_cgc_cli4 as cgc4,a.cli_dup_cgc_cli2 as cgc2,b.nome_cliente as cliente,
        sum(a.saldo_duplicata) as saldo_vencer
        --a.saldo_duplicata
from fatu_070 a, pedi_010 b
where a.codigo_empresa > 0
      and a.cli_dup_cgc_cli9 = b.cgc_9
      and a.cli_dup_cgc_cli4 = b.cgc_4
      and a.cli_dup_cgc_cli2 = b.cgc_2
      and (b.grupo_economico = &gru or b.grupo_economico = &gru2)
      and a.data_prorrogacao >= current_date - 1
      --and b.nome_cliente like 'naya je%'
      --and a.num_duplicata = 77486
group by a.cli_dup_cgc_cli9, a.cli_dup_cgc_cli4, a.cli_dup_cgc_cli2, b.nome_cliente
order by a.cli_dup_cgc_cli9, a.cli_dup_cgc_cli4, a.cli_dup_cgc_cli2, b.nome_cliente
  • 1

    I don’t know if I understand the question but in case "a" and "b" are aliases (nicknames) so refers to.data_extension instead of factu_070.data_extension

1 answer

3


Suppose the example we want to list the name of the Employee and their respective Position:

SELECT f.nome, d.cargo
FROM Funcionario f 
INNER JOIN Departamento d
ON F.IdCargo = D.IdCargo

Obserse that I used the letter 'f' to reference table columns Official, and the letter 'd' to reference table columns Department. I mean, I’ve done nothing but DUB the tables so that the code SQL did not become extensive. This code below would get the same result without using the nicknames, in which we call 'alias'. Would look like this

SELECT Funcionario.nome, Departamento.cargo
FROM Funcionario 
INNER JOIN Departamento
ON Funcionario.IdCargo = Departamento.IdCargo

I hope I’ve helped.

  • @Andersondefreitasmigloranza if the answer helped you, please mark as answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.