1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Django select only rows with duplicate field values

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 17, 2024 às 04:23.

  1. Stack

    Stack Membro Participativo

    suppose we have a model in django defined as follows:

    class Literal:
    name = models.CharField(...)
    ...


    Name field is not unique, and thus can have duplicate values. I need to accomplish the following task: Select all rows from the model that have at least one duplicate value of the name field.

    I know how to do it using plain SQL (may be not the best solution):

    select * from literal where name IN (
    select name from literal group by name having count((name)) > 1
    );


    So, is it possible to select this using django ORM? Or better SQL solution?

    Continue reading...

Compartilhe esta Página