Skip to content

Instantly share code, notes, and snippets.

@alexwoolford
Last active August 29, 2015 14:07
Show Gist options
  • Save alexwoolford/0c304e6c0665a26ddbb6 to your computer and use it in GitHub Desktop.
Save alexwoolford/0c304e6c0665a26ddbb6 to your computer and use it in GitHub Desktop.
Stackoverflow: why-when-add-where-clause-in-sql-statement-query-return-no-data
#http://stackoverflow.com/questions/26500406/why-when-add-where-clause-in-sql-statement-query-return-no-data
"""
create table tb_test
(
id integer,
name varchar(255),
date date
);
insert into tb_test (id, name, date) values (0,'Mike','2014-04-24');
insert into tb_test (id, name, date) values (1,'Mick','2014-04-25');
insert into tb_test (id, name, date) values (2,'Marta','2014-04-26');
"""
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", db="test")
cur=db.cursor()
cur.execute("SELECT id,name, date FROM `tb_test` where id > 1 ")
for row in cur.fetchall():
id = str(row[0])
name = str(row[1])
print "id " + id + " name " + name
# script returns: id 2 name Marta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment