Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql problem in a joint query

Posted on 2002-04-29
4
Medium Priority
?
588 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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6976823
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 200 total points
ID: 6977987
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
ID: 6980289
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
ID: 6980584
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

963 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