Jump to content

QUERY HELP using two tables


JJR

Recommended Posts

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,

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.