Solved

sql problem in a joint query

Posted on 2002-04-29
4
582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
asp syntax 3 66
Adding Row and Cell on a table 14 28
Display field if column exists 7 32
Read text on Table 7 25
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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