Solved

Referencing the same column from table aliases

Posted on 2004-03-31
1
162 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now