Re: [sqlite] looping over a result set in a query

2008-02-09 Thread Alexander Batyrshin
> Is it possible to refine/combine the above two sets of queries into one? Yes. It's possible: A) SELECT e.to_node_id AS node_id FROM edge e WHERE e.from_node_id = $node_id UNION SELECT e.from_node_id AS node_id FROM edge e WHERE e.to_node_id = $node_id B) SELECT c

Re: [sqlite] looping over a result set in a query

2008-02-09 Thread P Kishor
ok, after embarrassedly realizing that I phrased my question terribly (thanks Alexander), here is a simplification and rewording of it -- (a) First I find all the "other nodes" in edges where a given $node_id is either the from_node_id or to_node_id. SELECT node_id, node_name FROM ( SELEC

Re: [sqlite] looping over a result set in a query

2008-02-09 Thread Alexander Batyrshin
For your pseudo-code for (b) i can suggest this, but i still not understand why you need it :-/ SUBQUERY = SELECT e.to_node_id AS node_id FROM edge e WHERE e.from_node_id = $node_id UNION SELECT e.from_node_id AS node_id FROM edge e WHERE e.to_node_id = $node_id

Re: [sqlite] looping over a result set in a query

2008-02-09 Thread Alexander Batyrshin
Hello Kishor, a: if you want to find all edges, why your query returns nodes? So I think it should be like this: SELECT edge_id FROM edge WHERE from_node = $node OR to_node = $node; This query is not good, because "OR" drop out any index optimization. But As I see your example doesn't have ind

[sqlite] looping over a result set in a query

2008-02-09 Thread P Kishor
I have a table of nodes and edges like so CREATE TABLE edge ( edge_id INTEGER PRIMARY KEY, from_node_id TEXT, to_node_id TEXT, .. ); CREATE TABLE node ( node_id INTEGER PRIMARY KEY, node_name TEXT, .. ); Given a $node_id, I want to find (a) all th