Using PHP and MySQL query results.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    Using PHP and MySQL query results.

    I have two results which I got after performing two and I want to left join those two tables, will this work. e.g.

    [CODE]
    $query1 = "select sample__code, location from sample";
    $query2 = "select sample_code, value from ion_data where ion_id = 1";
    $result1 = mysql_query($qu ery1);
    $result2 = mysql_query($qu eyr2);

    //How do I perform a left join between the two

    //or will this work
    $query = '( $query1 left join $query2 where sample.sample_c ode = ion_data.sample _code)';
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can just write one sql string with the left join. There's no need to separate them and then try to join them afterwards.

    Comment

    • thatos
      New Member
      • Aug 2007
      • 105

      #3
      But for ease of use can't I just have different statements and then concatenate those strings to form the final query?

      Comment

      • thatos
        New Member
        • Aug 2007
        • 105

        #4
        Or it this possible.
        Code:
        $query = "(select s,m from R left join select s,n from P where R.s = P.s) left join select s,p from A where ?.s = A.s";

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          That's not syntactically correct SQL so no, you can't use that exactly. But in concept, you can do that.

          Comment

          Working...