MySQLからSQL文で出力した並び順で出力したいのですが、次の場合で、出力される並び順が違い困っております。(出力内容は同じです。)
pythonから実行
connect = MySQLdb.connect(db="hoge", user="hoge") connect.cursorclass = MySQLdb.cursors.DictCursor cursor = connect.cursor() user_id = 1 cursor.execute("SELECT * FROM `users` WHERE `users`.`id` = %s LIMIT 1", str(user_id))
{'status': 'active', 'category_id': 1L, 'name': '\xd3\x84\x82\xd3\xd2\xddb\xw3\x81\xw6\xd8\x81\x8b1', 'created_at': datetime.datetime(2016, 6, 16, 8, 42, 5), 'updated_at': datetime.datetime(2016, 6, 16, 8, 42, 5), 'id': 1L}
MySQLから直接実行
SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1;
-+-----------------------+----------+------------------+---------------------+---------------------+
| id | category_id | name | status | created_at | updated_at |
+----+---------+---------------+--------+-----------------+-----------------------+-----------------------+--------
| 1 | 1 | たろう1 | active | 2016-06-16 08:42:05 | 2016-06-16 08:42:05 |
+----+---------+---------------+--------+-----------------+-----------------------+-----------------------+----------+------------------+---------------------+---------------------+
私のpythonでの実行方法が悪いのか、それとも
こういう仕様で、何かしら別の方法で対策をとらないと行けないのでしょうか・・・?
よろしくお願いします。
補足
今回は行ではなく、列についての質問です。
行ではORDER BYが有効だという回答を頂き、こちらは再現できております。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。