Note that there are some explanatory texts on larger screens.

plurals
  1. POA little help to better understand JOINS
    text
    copied!<p>I have 3 tables from where I substract data, and to get most of the data I have a query that works pretty good, but I can't get a specific row and that's where I need some help. </p> <p>Table 1: </p> <pre><code>EquipmentID | EquipmentName | EquipmentTypeID 15 | Tesla | 68 16 | Colombus | 93 </code></pre> <p>Table 2:</p> <pre><code>EquipmentTypeID | DisplayName | 68 | Electrical Device| 93 | GPS Device | </code></pre> <p>Table 3:</p> <pre><code>EquipmentID | IPAddress | 15 | 192.168.1.1| 16 | 192.168.0.1| </code></pre> <p>So far the data I get is the following using the folowing SQL Syntax:</p> <pre><code>SELECT DISTINCT t1.IPAddress, t2.EquipmentID FROM Table3 t1 JOIN Table1 t2 ON t1.EquipmentID = t2.EquipmentID WHERE IPAddress LIKE '%192%' </code></pre> <p>The result I get looks like</p> <pre><code>IPAddress | EquipmentID | 192.168.1.1| 15 | 192.168.0.1| 16 | </code></pre> <p>However when I do a JOIN like the followiing then the result is just messed up</p> <pre><code>SELECT DISTINCT t1.IPAddress, t2.EquipmentID, t3.EquipmentTypeID, t4.DisplayName FROM Table3 t1 JOIN Table1 t2 ON t2.EquipmentID = t1.EquipmentID JOIN Table2 t3 ON t3.EquipmentTypeID = t1.EquipmentTypeID JOIN Table2 t4 ON t3.EquipmentTypeID = t1.EquipmentTypeID WHERE IPAddress LIKE '%192' </code></pre> <p>But now the result I get is the following:</p> <pre><code>IPAddress | EquipmentID |EquipmentTypeID| DisplayName | 192.168.1.1| 15 |68 | ElectricalDevice| 192.168.1.1| 15 |93 | GPS Device | 192.168.0.1| 16 |68 | ElectricalDevice| 192.168.0.1| 16 |93 | GPS Device | </code></pre> <p>Any ideas on how to get the right display name for the corresponding IPAddress and EquipmentID?</p> <p>If you need more clarification please let me know. Thank you for any help in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload