How do I select multiple fields in the same query?

3

I created a dummy bank with the following structure:

BelowarealsothenumberedSQLServerscriptsforcreatingthedatabase,ifneeded.

SQL Fiddle

Now, what I want is to make a query where they are shown:

  • The limit of an additional holder - present in the table Additional Headers
  • The name of this client - present in the Client table
  • The relationship of this customer - also in Additional Headlines
  • Who this holder depends on - also on the Client table, referenced in the Account table
  • asked by anonymous 05.09.2015 / 22:00

    1 answer

    2

    If I understand, this is more or less (I hope I have not interpreted anything wrong):

    SELECT Titulares_Adicionais.Limite, Titulares_Adicionais.Grau_Parentesco,
        Conta.Cod_Titular, Cliente.Nome
    FROM Titulares_Adicionais
    INNER JOIN Conta ON Titulares_Adicionais.Cod_Conta = Conta.Codigo
    INNER JOIN Cliente ON Titulares_Adicionais.Cod_Cli = Cliente.Codigo
    WHERE Titulares_Adicionais.Cod_Cli = 5;
    

    See running SQLFiddle .

    In the background the first INNER JOIN is unnecessary there, but I left it if you want to sophisticate and want to get information from it, it's easy. Note that no data is taken from the Conta table, so it is not necessary.

    The second is necessary because it takes Nome there in the Cliente table.

    The INNER JOIN or just JOIN is that it lists the tables you need based on the columns you set.

        
    06.09.2015 / 01:35