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.
Table 1:
EquipmentID | EquipmentName | EquipmentTypeID
15 | Tesla | 68
16 | Colombus | 93
Table 2:
EquipmentTypeID | DisplayName |
68 | Electrical Device|
93 | GPS Device |
Table 3:
EquipmentID | IPAddress |
15 | 192.168.1.1|
16 | 192.168.0.1|
So far the data I get is the following using the folowing SQL Syntax:
SELECT DISTINCT t1.IPAddress,
t2.EquipmentID
FROM Table3 t1
JOIN Table1 t2 ON t1.EquipmentID = t2.EquipmentID
WHERE IPAddress LIKE '%192%'
The result I get looks like
IPAddress | EquipmentID |
192.168.1.1| 15 |
192.168.0.1| 16 |
However when I do a JOIN like the followiing then the result is just messed up
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'
But now the result I get is the following:
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 |
Any ideas on how to get the right display name for the corresponding IPAddress and EquipmentID?
If you need more clarification please let me know. Thank you for any help in advance