Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQLite Query in Python
#1
I have created a table named "G" with python but I am not sure how to select the data.

Below is the table:
Parent:--Child:
c----------a
a----------b
a----------e
c----------d
c----------f
f----------g
f----------h
h----------j
h----------i

Example:
c have 3 children: a,d,f
a have 2 children: b,e

What I want to do is to show the parent if the two given children are correct.
For example:
Given "e" and "b" will show the parent "a"
Given "j" and "i" will show the parent "h"
Given "h" and "i" will show None because their parent are not the same.

What I tried to do is:
Given "e" and "b", should print out "a": (PS: G is the name of the table)

SELECT G.Parent FROM G WHERE G.Child == "e" #this line print "a"

SELECT G.Parent FROM G WHERE G.Child == "b" #this line print "a"

I think this line's logic is correct and it should work, however,
SELECT G.Parent FROM G WHERE G.Child == "e" AND G.Child =="b" #this line print NONE

Also, I tried:
SELECT G.Parent FROM G WHERE G.Child == "e" OR G.Child =="b", this line print "a"
But when two letter do not have the same parent it will not print NONE, it print the first one's parent.
Reply
#2
IDK too much about tables but read here and you'll probably find the answer you're looking for - http://docs.astropy.org/en/stable/table/...table.html
Reply
#3
can you post an SQL dump (small please) of the table
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with data analysing with python and sqlite Hardcool 2 300 Jan-30-2024, 06:49 AM
Last Post: Athi
  python sqlite autoincrement in primary column janeik 6 1,076 Aug-13-2023, 11:22 AM
Last Post: janeik
  list the files using query in python arjunaram 0 652 Mar-28-2023, 02:39 PM
Last Post: arjunaram
  python sql query single quote in a string mg24 1 996 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  "SUMIF" type query in Python (help required) BlainEillimatta 0 805 Oct-06-2022, 09:08 AM
Last Post: BlainEillimatta
  Help with subtracting values using SQLite & Python Extra 10 3,288 May-10-2022, 08:36 AM
Last Post: ibreeden
  [Solved]Help with search statement-SQLite & Python Extra 1 1,016 May-06-2022, 07:38 PM
Last Post: Extra
  Help With Python SQLite Error Extra 10 14,558 May-04-2022, 11:42 PM
Last Post: Extra
  Python Sqlite georgebijum 0 1,030 May-04-2022, 10:12 AM
Last Post: georgebijum
  MSSQL query not working in Python kat35601 0 874 Apr-12-2022, 06:44 PM
Last Post: kat35601

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020