Reputation: 926
Trying to list sqlite3 value from highest to lowest limited it to 10 using python, here's my current code
connection = sqlite3.connect('mydb.db')
database = connection.cursor()
all_user = str(database.execute("SELECT logtext from logs order by logtext limit 10 ")
I can't figure the logic of using len(logtext) and how to actually list from highest to lowest limiting them by 10.
Upvotes: 0
Views: 66
Reputation: 485
Try
connection = sqlite3.connect('mydb.db')
cursor = connection.cursor()
cursor.execute("SELECT logtext from logs order by length(logtext) desc limit 10")
results = cursor.fetchall()
See also https://stackoverflow.com/a/3606923/960709
Upvotes: 1