tags:

views:

50

answers:

3

Hi Guys, I have a tables like this

Results
-------
id        - autoincrement value
TestCase  - varchar
Verdict   - varchar
AppID     - varchar

TestCases
---------
id                 - autoincrementr value
TestCase           - varchar
TestCase_container - varchar

Basically I am displaying the results in php code. while displaying the testcase, I am storing the testcase in a variable. in the while loop of mysql_query, I am creating another connection to DB and passing this variable to TestCases table to get the TestCase_Container assiciated with it. This is a long way of doing this but I am unable to figure out proper direct SQL query using join or any other thing. Can someone point me in right direction please?

Thanks,

+2  A: 

LIke this?

select r.id,r.TestCase,r.Verdict,r.AppId,tc.TestCase_container 
 from Results r,TestCases tc 
 where Results.TestCase=TestCases.TestCase

For DB normalization, results table must have testcase_id field instead of TestCase

yu_sha
Er, this solution too :D
pssdbt
A: 

Kind of hard to say, but I think what you're trying to do is a query like this maybe?

SELECT b.id AS result_id, a.TestCase, b.Verdict, b.AppID, a.id AS testcase_id, a.TestCase_container
FROM TestCases a
LEFT JOIN Results b
  ON b.TestCase = a.TestCase;

Would probably be better to be joining on an indexed integer/id field, but that would work fine.

pssdbt
A: 

You could easily select all data from your tables by this SQL query:

SELECT Results.TestCase AS TestCase, Results.Verdict AS Verdict, Results.AppID AS AppID, TestCases.TestCase_container AS Container FROM Results JOIN TestCases ON Results.TestCase = TestCases.TestCase

After you should iterate getted array of values in any loop (for example while) like that:

$query = "SELECT Results.TestCase, Results.Verdict, Results.AppID, TestCases.TestCase_container FROM Results JOIN TestCases ON Results.TestCase = TestCases.TestCase";
$res = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($res)) {
    echo $row['TestCase'], ":", $row['Verdict'], ":", $row['AppID'], ":", $row['Container'], "\n";
}
Sergey Kuznetsov