{"id":4465,"date":"2023-11-29T15:10:57","date_gmt":"2023-11-29T15:10:57","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4465"},"modified":"2023-11-29T20:44:53","modified_gmt":"2023-11-29T20:44:53","slug":"select-queries","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/database\/sqlite\/queries\/select\/select-queries","title":{"rendered":"SELECT queries"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">SELECT query example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    db1cursor.execute(\"\"\"SELECT * FROM my_table \n                      WHERE some_column = ?\n                      \"\"\",(my_value1,))\n    rows = db1cursor.fetchall()\n    for row in rows:\n        #print(row)\n        print(\"my_column0: \", row&#91;0])       #Results are returned in the order used within the SELECT statement, or within the table for *\n        print(\"my_column1: \", row&#91;1])\n        print(\"my_column2: \", row&#91;2])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Single row result<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    db1cursor.execute(\"\"\"SELECT * FROM my_table \n                      WHERE some_column = ?\n                      \"\"\",(my_value1,))\n    row = db1cursor.fetchone()\n    if row != None:\n        print(\"my_column0: \", row&#91;0])\n        print(\"my_column1: \", row&#91;1])\n        print(\"my_column2: \", row&#91;2])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Returning results as a dictionary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    db1cursor.execute(\"\"\"SELECT my_column_b, my_column_c, my_column_d FROM my_table \n                      WHERE some_column = ?\n                      \"\"\",(my_value1,))\n    row = db1cursor.fetchone()\n\n    result = {\"my_column_b\": row&#91;0], \"my_column_c\": row&#91;1], \"my_column_d\": row&#91;2]}\n    #print(result)\n    return(result)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SELECT query example Single row result Returning results as a dictionary<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[357],"tags":[],"class_list":["post-4465","post","type-post","status-publish","format-standard","hentry","category-select"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4465"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4465\/revisions"}],"predecessor-version":[{"id":4489,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4465\/revisions\/4489"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}