Django MySQL distinct query for getting multiple values

后端 未结 2 1944
陌清茗
陌清茗 2020-12-09 19:37

I have a MySQL database unfortunately used with Django 1.4.1. Distinct function is only working for POSTGRESQL if i get it right.

2条回答
  •  庸人自扰
    2020-12-09 19:50

    .distinct([*fields]) only works in PostgresSQL.

    From distinct documentation

    Here's the difference. For a normal distinct() call, the database compares each field in each row when determining which rows are distinct. For a distinct() call with specified field names, the database will only compare the specified field names.

    As stated all fields in a record are checked. Mostly likely in your case you are getting records with different field values (more likely a case if you are queries multiple tables ManyToMany or ForeignKey relations).

    For consolidating as array you can refer your earlier question Django Query distinct values works but i cant use the query result

提交回复
热议问题