JJR Posted April 16, 2008 Share Posted April 16, 2008 Hey everyone, kinda new to this sql stuff and need help building a query. I have two tables one called nodes and the other called cnodes.the nodes table stores information on the node and the cnode table contains the 2 nodes that are connected. i need a query to go in to the cnode nodes check two conencted nodes and takes their number and then go in and take the lat and lng from nodes table and pass to vairables for a calculation. how hard would this be? cos i have been working on it and cant gettin nothin to work Thanks, Quote Link to comment Share on other sites More sharing options...
fenway Posted April 16, 2008 Share Posted April 16, 2008 Could you post the table structure? Sounds like you're going to need to join in the nodes table twice. Quote Link to comment Share on other sites More sharing options...
JJR Posted April 16, 2008 Author Share Posted April 16, 2008 node table: node, name, lat, lng cnode table is: node1, node2, distance is that what you mean? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 16, 2008 Share Posted April 16, 2008 How do you figure out which cnode record to use/ Quote Link to comment Share on other sites More sharing options...
JJR Posted April 16, 2008 Author Share Posted April 16, 2008 should I add an id field? I didnt explain the whole problem. the distance field in the cnode table is empty. I need the lat and lng for the node1 and node2 from the node table to put through a calculation algorithm and then put the answer in the distance field in the cnode field, but have no idea how to start. could u help? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 16, 2008 Share Posted April 16, 2008 But the cnode table already has node1 and node2? If so, then select * from cnode as c inner join node as n1 on ( n1.node = c.node1) inner join node as n2 on ( n2.node = c.node2) Will get you all of the pairs -- it's not hard to convert this select statement into and update statement. Quote Link to comment Share on other sites More sharing options...
JJR Posted April 16, 2008 Author Share Posted April 16, 2008 Hey im still lost. should I not be creating a loop to go in and go through each row in the cnodes table....taking the value in node1 and the value in node2 looking up the node table and picking up the two sets of lat and lng. then passing these lat and lngs into lat1, lng1, lat2, lng2 and then doing the calculation. maybe im not explaining it correctly. JJR Quote Link to comment Share on other sites More sharing options...
fenway Posted April 17, 2008 Share Posted April 17, 2008 Hey im still lost. should I not be creating a loop to go in and go through each row in the cnodes table....taking the value in node1 and the value in node2 looking up the node table and picking up the two sets of lat and lng. then passing these lat and lngs into lat1, lng1, lat2, lng2 and then doing the calculation. maybe im not explaining it correctly. JJR No need... a JOIN replaces this loop... and you can do the calcluation in mysql... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.