SQL Nested Doubt

0

I'm using this SELECT , but now I need to search the customer table for the fields (eg cli_clifone and cli_clicontato ), how can I include it to bring this information to SELECT below, I'm trying however only returns me error:

SELECT cli_cdcli, cli_razsoc
 From
 (
 SELECT cli_cdcli, cli_razsoc FROM vw_os_finalizada_cliente
 Union
 SELECT cli_cdcli, cli_razsoc FROM vw_titrec_aberto_cliente
 ) AS ConCli
 GROUP BY ConCli.cli_cdcli
 ORDER BY ConCli.cli_razsoc, ConCli.cli_cdcli
    
asked by anonymous 23.08.2018 / 20:54

1 answer

0

For the little that you informed I would do it like this:

SELECT cli_cdcli, cli_razsoc, A.cli_clifone, A.cli_clicontato
From
(
SELECT cli_cdcli, cli_razsoc FROM vw_os_finalizada_cliente
Union
SELECT cli_cdcli, cli_razsoc FROM vw_titrec_aberto_cliente
) AS ConCli
INNER JOIN (tabela de cliente original) as A ON (A.cli_cdcli=ConCli.cli_cdcli)
GROUP BY ConCli.cli_cdcli
ORDER BY ConCli.cli_razsoc, ConCli.cli_cdcli, A.cli_clifone, A.cli_clicontato

As you already have the right customers through the view and can not add the other information, I believe it would be the easiest way.

    
29.08.2018 / 14:54