Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 JOIN question for a pro

Author  Topic 

knudmt
Starting Member

12 Posts

Posted - 2010-04-21 : 23:29:25
Hello I am new to the forum and a beginner with SQL. I have an Internet programming assignment that is on the brink of completion. Problem is that I have to retrieve some info from the DB in a tricky way.

here are the two tables:

[tblPaths]
PK PathID
poiAID
poiBID
-------------------
[tblPointOfInterest]
PK ID
GPSLat
GPSLon
-------------------
I am trying to retrieve the GPSLat and GPSLon for poiAID and poiBID.
the statement that should work but doesnt is this:

SELECT tblPaths.poiAID, tblPaths.poiBID, tblPointOfInterest.GPSLat, tblPointOfInterest.GPSLon
AS myLocations
FROM tblPaths, tblPointOfInterest
WHERE tblPaths.poiAID = tblPointOfInterest.ID AND tblPaths.poiBID = tblPointOfInterest.ID

I get no output. However when I use the OR operator I get some output. What is the problem?? I am beating my head against the wall here! I have a feeling it has to do with both poi IDs pointing to one ID.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 23:38:49
[code]
SELECT p.poiAID, p.poiBID, a.GPSLat, a.GPSLon,b.GPSLat, b.GPSLon
AS myLocations
FROM tblPaths p
JOIN tblPointOfInterest a
ON p.poiAID = a.ID
JOIN tblPointOfInterest b
ON p.poiBID = b.ID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

knudmt
Starting Member

12 Posts

Posted - 2010-04-22 : 01:19:31
WOW you are my new HERO!
That worked wonderfully!
I never thought of using two joins. Brilliant. You have no idea how much you have increased my knowledge level as well as saved my butt on this project!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-22 : 04:57:21
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -