Re: SQL Join problem (Firebird)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Evan Morris wrote:
Hi all

Say you have two tables, TABLE1 and TABLE2. Each table contains (amongst
others) a field called SOMEVALUE

Now, in TABLE1 SOMEVALUE contains "string1", but in TABLE2 SOMEVALUE
contains "string2".

Now you join these tables (on SOMEOTHERVALUE) and you loop through the
results set:

while ($row = ibase_fetch_object($sth)) {
    echo "$row -> SOMEVALUE<br>";
    };

This only echoes the value of SOMEVALUE last referred to in your SQL
statement (obviously, because it has no way of differentiating between the
two versions of SOMEVALUE).

However, it does not work to do

echo "$row->TABLE1.SOMEVALUE<br>";

This has unexpected results (it echoes the literal text SOMEVALUE).



alias the columns to a different name using the keyword 'as'
SELECT t1.SOMEVALUE as somevalue1, t1.SOMEOTHERVALUE, t2.SOMEVALUE as somevalue2, t2.SOMEOTHERVALUE from TABLE1
t1 JOIN TABLE2 t2 ON t1.SOMEOTHERVALUE = t2.SOMEOTHERVALUE


echo $row->somevalue1

echo $row->somevalue2

--

Sean

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux