Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

425
Visualizações
Why Sub query in leftjoin in typeorm giving me error?

If i am defining innerjoin or leftjoin in subquery of leftjoinandselect, then it is giving me error sqlMessage: "Duplicate column name 'id'".

For example

.leftJoinAndSelect(
            (qb) =>
              qb
                .from(Email, 'email')
                .innerJoin(User, 'user')
                .where('user.account = :account', {
                  accountId: 4,
                }),
            'email',
            '`email`.`id` = 1',
          )

The above will give me error "Duplicate column name 'id'"

But if i remove innerJoin then it is working fine and giving expected result.

.leftJoinAndSelect(
                (qb) =>
                  qb
                    .from(Email, 'email'),
                'email',
                '`email`.`id` = 1',
              )

Any idea why is it giving me this error.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the problem is that both email and user tables have id columns. Can you try the following code?:

.leftJoinAndSelect(
            (qb) =>
              qb    
                .select("user.id", "user_id")
                .addSelect("email.id", "email_id")
                // Add whatever you want by .addSelect method
                .from(Email, 'email')
                .innerJoin(User, 'user')
                .where('user.account = :account', {
                  accountId: 4,
                }),
            'email',
            '`email`.`id` = 1',
          )
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda