I have the following sql query which I found on the web, if it worked correctly it would be perfect, but it's not adhering to the where clause.
SELECT *
FROM Chicken AS a,
(SELECT MIN(Temp) AS mini, MAX(Temp) AS maxi
FROM Chicken
) AS m
WHERE m.maxi = a.Temp AND `Location` = "Outside" OR m.mini = a.Temp AND `Location` = "Outside"
ORDER BY `a`.`Time` DESC Limit 1
what is happening is that it's taking the lowest and the highest temperature regardless of location. I need it to find the lowest and highest temperature for the location 'Outside'.
Can anyone help?
SELECT *
FROM Chicken AS a,
(SELECT MIN(Temp) AS mini, MAX(Temp) AS maxi
FROM Chicken
) AS m
WHERE (m.maxi = a.Temp AND `Location` = "Outside") OR (m.mini = a.Temp AND `Location` = "Outside")
ORDER BY `a`.`Time` DESC Limit 1
Try this may be its works for you.