Duplicate records in psycopg2 and postgresql query

0

I ask for help, with this code that has been spinning around me for a while:

def Liquidarnomina():
    cur = conn.cursor(cursor_factory=RealDictCursor)

            cur.execute(""" select distinct id_Emp, (nombre1Emp||' '||nombre2Emp||' '||apell1Emp||' '||apell2Emp) as nombre, numdocEmp, sbmEmp, 
                            hod
                            from empleado, novedad_nomina
                            where numdocEmp=empleado.numdocEmp
                            group by  id_emp, nombre, numdocEmp, sbmEmp, hod, hon""")

            liqnom = [cur.fetchall()]

            for row  in liqnom :
                print(tabulate(row, headers="keys", tablefmt='fancy_grid', stralign='left'))

            #return sbm_ln
            #print(sbm_ln )


            os.system('cls')
            print("=============================================================================================")
            print("la liquidacion ha sido Agregada!!!")
            print("")



╒═════════════╤═══════════════════╤══════════════╤═══════════════════════════════════╤════════════════╤═══════╤═══════╤═══════╤═══════╤════════╤════════╤════════╤════════╤════════════╤════════════════╤══════════════╤═════════════════╤═════════════════╕
│   id_novnom │   periodo_novedad │   num_pernov │ nom_pernov                        │   numdocempnov │   hod │   hon │   hed │   hen │   hofd │   hofn │   hefd │   hefn │   diastmes │   diasincapmes │ diasvacmes   │ desc_prestnom   │ otros_descnom   │
╞═════════════╪═══════════════════╪══════════════╪═══════════════════════════════════╪════════════════╪═══════╪═══════╪═══════╪═══════╪════════╪════════╪════════╪════════╪════════════╪════════════════╪══════════════╪═════════════════╪═════════════════╡
│           1 │            201801 │            1 │ PRIMERA QUINCENA DE ENERO DE 2018 │     1035225250 │   240 │     2 │     1 │     5 │      2 │      1 │     25 │     12 │         30 │              4 │ $5.00        │ $25,000.00      │ $15,000.00      │
├─────────────┼───────────────────┼──────────────┼───────────────────────────────────┼────────────────┼───────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────────┼────────────────┼──────────────┼─────────────────┼─────────────────┤
│           2 │            201802 │            1 │ PRIMERA QUINCENA DE ENERO DE 2018 │     1029230415 │   240 │     5 │     5 │     5 │      5 │      5 │      5 │      5 │         30 │              6 │ $2.00        │ $2,000.00       │ $3,000.00       │
╘═════════════╧═══════════════════╧══════════════╧═══════════════════════════════════╧════════════════╧═══════╧═══════╧═══════╧═══════╧════════╧════════╧════════╧════════╧════════════╧════════════════╧══════════════╧═════════════════╧═════════════════╛
  

up here, all right, but when I try to add another column as (hon) duplicate the records of the query

cur.execute(""" select distinct id_Emp, (nombre1Emp||' '||nombre2Emp||' '||apell1Emp||' '||apell2Emp) as nombre, numdocEmp, sbmEmp, 
                            hod, hon.....

>

╒══════════╤════════════════════════════╤═════════════╤═════════════╤═══════╤═══════╕
│   id_emp │ nombre                     │   numdocemp │ sbmemp      │   hod │   hon │
╞══════════╪════════════════════════════╪═════════════╪═════════════╪═══════╪═══════╡
│        2 │ PEDRO LUIS ALBARRACIN MENA │  1035225250 │ $950,000.00 │   240 │     2 │
├──────────┼────────────────────────────┼─────────────┼─────────────┼───────┼───────┤
│        2 │ PEDRO LUIS ALBARRACIN MENA │  1035225250 │ $950,000.00 │   240 │     5 │
├──────────┼────────────────────────────┼─────────────┼─────────────┼───────┼───────┤
│        3 │ JULIA MARIA MENA PALACIO   │  1029230415 │ $975,000.00 │   240 │     2 │
├──────────┼────────────────────────────┼─────────────┼─────────────┼───────┼───────┤
│        3 │ JULIA MARIA MENA PALACIO   │  1029230415 │ $975,000.00 │   240 │     5 │
╘══════════╧════════════════════════════╧═════════════╧═════════════╧═══════╧═══════╛
  

the query is about two tables (employee, new_nomin) that have many more records, I can not overcome this doubt, I do not know what I lack thanks, thanks.

    
asked by Jsierra2017 19.03.2018 в 19:37
source

0 answers