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

x
?
Solved

Referencing the same column from table aliases

Posted on 2004-03-31
1
Medium Priority
?
204 Views
Last Modified: 2008-03-06
These tables don't make a lot of sense, but they are for illustrative purposes only:

FactTable:
ID | Result
1     Dead
2     Alive
3     Open

RefTable
Name | FactID1 | FactID2
Jane     1             2
Bob      1             3

$query = "select Name, Res1.Result, Res2.Result from RefTable, FactTable Res1, FactTable Res2
               where RefTable.Fact1ID = Res1.ID and RefTable.Fact2ID = Res2.ID"

$res = mssql_query($query);
$n = mssql_num_rows($res);
if ($n)
{
   $a = mssql_fetch_array($res);
   $name = $a['Name'];
   // MY QUESTION: how do I reference Res1.Result and Res2.Result here? $a['Result'] won't work,
   // it's ambigous. Also fully qualified $a['Res1.Result'] does not work. What is the correct syntax?
}

Thanks!
0
Comment
Question by:RichardFox
1 Comment
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 500 total points
ID: 10726758
> $query = "select Name, Res1.Result, Res2.Result from RefTable, FactTable
> Res1, FactTable Res2
>                where RefTable.Fact1ID = Res1.ID and RefTable.Fact2ID = Res2.ID"

query can be changed to...

$query = "select Name, Res1.Result as Result1, Res2.Result as Result2 from RefTable, FactTable Res1, FactTable Res2
               where RefTable.Fact1ID = Res1.ID and RefTable.Fact2ID = Res2.ID"


.
.
$val = $a['Result1']

Cheers!
venkat.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

877 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