Solved

sql problem in a joint query

Posted on 2002-04-29
4
580 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]
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML in email body has extra  tick marks 3 77
JQuery to parse xml string and get element by id 4 35
Select only the top record in a left join 13 36
ASP/VB email question 4 35
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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