Solved

Referencing the same column from table aliases

Posted on 2004-03-31
1
150 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
Comment Utility
> $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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

8 Experts available now in Live!

Get 1:1 Help Now