I have this table
Configuration
ID Location Position CheckData UpdateDT
1 House1 Floor1 20 2020-06-24 18:12:20
2 House1 Floor1 30 2020-06-24 13:54:16
3 House1 Floor2 45 2020-06-24 10:06:34
4 House2 Roof1 70 2020-05-12 13:27:43
5 House1 Floor1 35 2020-05-12 12:20:12
I like to make a select
to get from the Configuration table only the latest updated values for each "home" and "position" e.g.
1 House1 Floor1 20 2020-06-24 18:12:20
3 House1 Floor2 45 2020-06-24 10:06:34
4 House2 Roof1 70 2020-05-12 13:27:43
i have try this, but its not working, because i dont know how to add the position on it
select * from Configuration where Location = 'house 1' order by Configuration.UpdateDT desc limit 1
and here is the php code that i have so far
$sqlsyntax = "SELECT * FROM `DevicesLocations`";
$resultfromsql = mysqli_query($connectionstring, $sqlsyntax);
while( $row = mysqli_fetch_array($resultfromsql) )
{
echo $row['Location'] . " " . $row['Comments'];
echo "<br />";
$sql2 = "SELECT * from Configuration where location='";
$sql2 = $sql2.$row['Location']."' order by UpdateDT desc limit 1";
echo $sql2."<br>";
$result2 = mysqli_query($connectionstring, $sql2);
while( $row2 = mysqli_fetch_array($result2) )
{
echo "..........".$row2['SensorPosition'] . " " . $row2['CheckData'] ;
echo "<br />";
}
echo "------------------------------<br>";
}
Output
House1 first home
...... floor1 20
House2 second home
...... Roof1 70
Desired Output
House1 first home
...... floor1 20
...... floor2 45
House2 second home
...... Roof1 70
If i use the following select
, how i can include the latest date?
SELECT * FROM `Configuration` group BY Configuration.SensorPosition