title: get data from two tables using sql inner join, Trying to get property of non-object
body: <p>I have two table events and session which looks like this </p>
  
  <p>Events table</p>
  
  <p><a href="https://i.stack.imgur.com/jDduN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jDduN.png" alt="enter image description here"></a></p>
  
  <p>Sessions table<a href="https://i.stack.imgur.com/b83zp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b83zp.png" alt="enter image description here"></a></p>
  
  <p>Here is expected results</p>
  
  <p><a href="https://i.stack.imgur.com/Azgam.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Azgam.png" alt="enter image description here"></a></p>
  
  <p>Here is my solution</p>
  
  <pre><code>  &lt;table&gt;
                    &lt;tr&gt;
                      &lt;th&gt;Sessions &lt;/th&gt;
                      &lt;th&gt;konto&lt;/th&gt;
                      &lt;th&gt;Mobile&lt;/th&gt;
                      &lt;th&gt;Komputer&lt;/th&gt;
                      &lt;th&gt;Date&lt;/th&gt;
                    &lt;/tr&gt;       
                    &lt;?php
                        $conn = mysqli_connect("localhost", "root", "", "ideabank_julia");
                        // Check connection
                        if ($conn-&gt;connect_error) {
                        die("Connection failed: " . $conn-&gt;connect_error);
                        }
                        $sql = "SELECT sid, datetime, count(*) as num_rows, count(distinct sid) as sessions,  
                        sum( targetbuttonname = 'konto' ) as num_konto,
                        sum(devicetype ='Computer') as num_computer, 
                        sum(devicetype = 'Mobile') as num_mobile from events
                        INNER JOIN sessions ON events.sid = sessions.sid group by sid, datetime;";
  
                        $result = $conn-&gt;query($sql);
                        if ($result-&gt;num_rows &gt; 0) {
                        // output data of each row
                        while($row = $result-&gt;fetch_assoc()) {
                        echo "&lt;tr&gt;
                        &lt;td&gt;". $row["num_rows"]."&lt;/td&gt;
                        &lt;td&gt;". $row["num_konto"]."&lt;/td&gt;         
                        &lt;td&gt;". $row["num_mobile"]. "&lt;/td&gt;
                        &lt;td&gt;". $row["num_computer"]. "&lt;/td&gt;
                        &lt;td&gt;". $row["datetime"]. "&lt;/td&gt;
  
                        &lt;/tr&gt;";
                        }
                        echo "&lt;/table&gt;";
                        } else { echo "0 results"; }
                        $conn-&gt;close();
                        ?&gt;
                  &lt;/table&gt;
  </code></pre>
  
  <p>Unfortunately when i run the script on phpmyadmin I am getting the following error</p>
  
  <pre><code> # 1052 - Column: 'sid' in field list is ambiguous
  </code></pre>
  
  <p>And when I run on php script above I get the following error</p>
  
  <pre><code>Trying to get property of non-object
  </code></pre>
  
  <p>What am I doing wrong in my code?</p>