I know that this is very similar to a lot of posts but I am attempting to writing a php query that connects to a Microsoft SQL Server. I can get it to bring all of the relevant data I want but when I put my where clause in the php query doesn't run. I have three tables
| MetalSource | MetalPrice | Currency |
In the metal prices table there is a date/time field which I want to find the latest date any date was put into the database regardless of time, how can this be done? My query is as follows:
$query = "SELECT mp.MetalSourceID, mp.UnitPrice, mp.DateCreated, mp.HighUnitPrice,
mp.PreviousUnitPrice, mp.PreviousHighUnitPrice,
mp.MetalSourceName, cu.Currency FROM tblMetalPrice AS mp
INNER JOIN tblMetalSource as ms ON mp.MetalSourceID = ms.MetalSourceID
INNER JOIN tblCurrency AS cu ON ms.CurrencyID = cu.CurrencyID
WHERE
SELECT MAX (DateCreated)
FROM mp"
Like i've said the SELECT statement works perfectly fine, but when I am trying to reduce the results with my WHERE clause it seems to die.
I've looked at all the other posts and tried several different things but nothing seems to be getting what I need.
Thanks
As per comments:
ORDER BY DateCreated DESC LIMIT 31
This will order the data and limit it by 31 rows.