I have 2 SQL tables, I need to pull the highest timestamp from the 2nd table and that timestamp needs to be within a range.
Table: Projects
ID,Name,invoiceTotal,department
1,Project1,100,1
2,Project2,200,3
3,Project3,300,2
4,Project4,100,2
5,Project5,400,1
Table: Manning
ProjectID,timestamp
1,1547038287
1,1515558287
1,1501118287
5,1471118287
5,1481118287
I have been playing about with using PHP to firstly run a query that has an inner join so i can pull both tables data.
SELECT
project.ID,
project.name,
project.invoiceTotal,
manning.timestamp
FROM
manning
INNER JOIN projects ON project.ID = manning.ProjectID
WHERE
project.department = 1 AND
manning.timestamp BETWEEN 1547038287 AND 1301118287
ORDER BY
manning.timestamp ASC
I'm then looping through with PHP and running procedural code to sort the data and then display it. The problem is it's slow, and it's definitely not the most efficient way of doing it.
So with this example data i would like to have the result:
1,Project1,100,1547038287
5,Project5,400,1481118287
I've been trying to use the "group by" however if the order of the manning table is not right i'm not getting the right results.
Thank you for any help. I've tried to use sqlfiddle.com however it seems to be down for me right now :(