Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:02:44+00:00 2026-06-09T01:02:44+00:00

When I do this queryset: Club.objects.values(‘district’).distinct() I expect to get this SQL: SELECT DISTINCT

  • 0

When I do this queryset:

Club.objects.values('district').distinct()

I expect to get this SQL:

SELECT DISTINCT `club_club`.`district` FROM `club_club` ORDER BY `club_club`.`name` ASC

But Django generates this query (adds ‘name’ column):

>>> print Club.objects.values('district').distinct().query
SELECT DISTINCT `club_club`.`district`, `club_club`.`name` FROM `club_club` ORDER BY `club_club`.`name` ASC

What is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:02:45+00:00Added an answer on June 9, 2026 at 1:02 am

    Query you are expecting is invalid order by column has to be in select list if you are using distinct keyword, or else you will get this standard SQL error

    Msg 145, Level 15, State 1, Line 1
    ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this QuerySet: brand = get_object_or_404(Brand, shortcut=shortcut) ads = Ad.objects.filter(mod__submodel__model__brand = brand).values('id') But
This is my query : set @agent_id = select agnt.id from agent agnt ,
Is there any way to remove select related from queryset? I found, that django
This line works and returns the value that I'm looking for: logs = Log.objects.filter(filterURI=aFilter.uri).values()[0]['yk']
This is in my urls.py: group_info = { 'queryset': Group.objects.all(), 'template_object_name': 'groups', 'paginate_by': 25,
In Django you can remove items from a QuerySet by doing this as documented
I have a ModelChoiceField in django forms: customField = forms.ModelChoiceField(queryset=MyModel.objects.filter(type=sometype)) But this queryset returns
I want to write a Django query equivalent to this SQL query: SELECT *
employee = Employee.objects.filter('age' = 99) We assume this queryset is empty. If I use
employees = Employee.objects.filter(age=23, sex='female') This would return a queryset. If I assume this queryset

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.