How to get a single record of a JOIN between 2 tables?

1

I happen to have 2 tables. One is the "main" table and another table where data is saved according to what is recorded in table 1. Table 1 will only have one record, while table 2 can have 2 or more records that depend on the record that was made in table 1.

When performing the JOIN, the number of records in table 2 is obtained, that is, the records in table 1 are repeated.

I have part of the solution, and it was using the aggregation function SUM (colum_name_TABLE2) , and grouping them by the ID of table 1. But, in one of the columns of table 2 the value will always be different, since it corresponds to the invoice number generated for each subscription that you made to the main record of table 1 ... At the end I need to show, the sum of one of the columns in table 2, and the different numbers of invoice that are located in another column of the same table 2.

How can I do?

    
asked by Nelson Sepulveda 26.02.2018 в 01:55
source

1 answer

1

I have not used Postgresql, but I have done something similar many times in MSSQL, I think the solution to your problem would be to concatenate the invoices by separating them by commas, so you could show as results the sum of one of the columns, and the separate invoices by commas. Here I leave an example that I found in postgres.

Concatenate with group By

I hope to be of help.

    
answered by 14.03.2018 / 18:47
source