Django
# Remove duplicate objects where there is more than one field to compare
https://stackoverflow.com/a/13700642
# Simple one-liner
UserProfile.objects.values('fullname').order_by().annotate(max_id=models.Max('owner_id'), count_id=models.Count('owner_id')).filter(count_id__gt=1)
# Print all SQL to console
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['console', ],
},