query help
Hello,
I have a querstion regarding subquerys to determine the key of the resulting array.
for example.
i have 2 tabels.
table1 with the collums
-> t1_Id
-> t1_Name
table2 with the collums
-> t2_Id
-> t1_Id (FK from t1)
-> t2_Value
to get te all data from table 2 for table 1 based on the t1_Id i would get a query somthing like:
SELECT t1.*, t2.* FROM table1 AS t1 LEFT JOIN tabel2 AS t2 ON t1.t1_Id = t2.t1_Id
and a print_r from php like:
array(
[t1_Id] => 1
[t1_Name] => test
[t2_Id] => 1
[t1_Id] => 1
[t2_Value]=> this is a test
)
now my problem is that i want the the value of [t1_Name] to be the key instead of [t2_Value] so it would be like this:
array(
[t1_Id] => 1
[t1_Name] => test
[t2_Id] => 1
[t1_Id] => 1
-> [test]=> this is a test
)
(i put an arrow to point out what i meant)
i know you kan do an AS statement like: t2.Value AS 'test' and get the result i want but the name test is variable.
So i need te change the key according to the [t1_Name] value.
is there a way to achief this with a single query.
(sorry for the typo's)
Subject
Views
Written By
Posted
query help
1584
April 01, 2011 06:04AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.