Solved

Referencing the same column from table aliases

Posted on 2004-03-31
1
192 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
[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
1 Comment
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 125 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

Independent Software Vendors: 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

623 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