Skip to content

Instantly share code, notes, and snippets.

View jwinf843's full-sized avatar

Jordan Winfery jwinf843

  • 豊中市ー大阪府ー日本
View GitHub Profile
@jwinf843
jwinf843 / gist:142a5bf152721d5f4fdc54f851913bd0
Created May 20, 2018 15:10 — forked from gladson/gist:1541450
sql to django queryset cheatsheet by pythonnewbie
Sql QuerySet Notes
SELECT count(*) FROM fruit Fruits.objects.count() table count
SELECT count(*) FROM fruit WHERE name=’Orange’ Fruits.objects.filter(name__exact=’Orange’).count() count with filter
SELECT * FROM fruit WHERE color is NULL Fruits.objects.get(color__isnull=True) filter by null
SELECT * FROM fruit WHERE color is NOT NULL Fruits.objects.get(color__isnull=False) filter by null
SELECT * FROM fruit WHERE name=’Apple’ Fruits.objects.get(name__exact=’Apple’) case sensitive
SELECT * FROM fruit WHERE lower(name)=lower(‘Apple’) Fruits.objects.get(name__iexact=’Apple’) case in-sensitive
SELECT * FROM fruit WHERE name LIKE ‘App%’ Fruits.objects.filter(name__startswith=’App’) case sensitive LIKE
SELECT * FROM fruit WHERE upper(name) LIKE ‘APP%’ Fruits.objects.filter(name__ista