I have a look-up table called Stations. I have a data table called Actual_Hourly_2004. Both tables have a field called FMFP_ID. There often is not data for every FMFP_ID in the Actual_Hourly_2004 table. However, I still want the FMFP_ID to be printed if there is not. I was told a Left Join was the way to go.
My SQL that I have been using just prints out the latest data for each station that actually has data:
$result = mysql_query ("SELECT * FROM Actual_Hourly_2004, Stations WHERE (Actual_Hourly_2004.FMFP_ID=Stations.FMFP_ID) AND (`Date_Valid` = '2004-03-18') AND (Stations.Forecast LIKE 'y') ORDER by 'Grp', 'Pos', 'Date_Valid', 'Time_Valid' DESC");
I simply replaced this line with my left join:
$result = mysql_query ("SELECT
Actual_Hourly_2004.FMFP_ID,
Actual_Hourly_2004.Temp,
Actual_Hourly_2004.Dew,
Actual_Hourly_2004.RH,
Actual_Hourly_2004.Time_Valid,
Actual_Hourly_2004.Date_Valid,
Actual_Hourly_2004.CDir,
Actual_Hourly_2004.WSdp,
Actual_Hourly_2004.WGst,
Actual_Hourly_2004.Rn_1,
FROM Stations
LEFT JOIN Actual_Hourly_2004 ON Actual_Hourly_2004.FMFP_ID=Stations.FMFP_ID");
Making no other changes to my code, this prints out nothing. Is it my SQL statement that is wrong, or is how I try to print the data?
I use things like $array[$FMFP_ID]['Time_Valid'] to print the data.
Many thanks.