Python Forum

Full Version: SQLite Query in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
can you post an SQL dump (small please) of the table