Solved

sql problem in a joint query

Posted on 2002-04-29
4
578 Views
Last Modified: 2010-05-18
Hi, all

I am using an SQL query in my asp file. In table Order: OrderId, StartPlaceId, EndPlaceId (Both placeIds are foreign keys of table Place). In table Place: PlaceId, PlaceName.

select O.OrderId, P.Name, Po.Name from Order as O, Place as P, Place as Po where O.StartPlaceId = P.PlaceId and O.EndPlaceId = Po.PlaceId

But it doesn't work. Could you please help me out? Thanks.

0
Comment
Question by:CodeLover
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
Hmmm i couldn't see anyting wrong?

Now, i would write the query like this (SQL Server):

select O.OrderId, Ps.Name as StartPlace, Pe.Name As EndPlace
from Order as O
join Place as Ps
on Ps.PlaceId = O.StartPlaceId
join Place as Pe
on Pe.PlaceId = O.EndPlaceId

Now, if you don't use SQL Server, please indicate your db.

Cheers
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 50 total points
Comment Utility
You don't have any "Name" field in the place table, I suppose it's "PlaceName" you want?

select O.OrderId, P.PlaceName, Po.PlaceName from Order as O, Place as P, Place as Po where O.StartPlaceId = P.PlaceId
and O.EndPlaceId = Po.PlaceId

or

select o.OrdertId, p.PlaceName, po.PlaceName
from Order o
inner join Place p on p.PlaceId=o.StartPlaceId
inner join Place po on po.PlaceId=o.EndPlaceId
0
 
LVL 1

Expert Comment

by:ramani_gr
Comment Utility
Actually the experts here are giving suggessions in a guess.  B'coz the question is not so clear.

The CodeLover has to say more here.  First of all, codelover has to say, whether is it giving any error, or is it giving unexpected rows or is it not giving any row.

What is the error or message or display you are getting.  We would go from there then.
0
 
LVL 29

Expert Comment

by:Göran Andersson
Comment Utility
No, ramani_gr, I was not guessing. The information is sufficient (assuming that it is correct), and the error is clear to see.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now