Solved

sql problem in a joint query

Posted on 2002-04-29
4
581 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 50 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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