mATOK Posted June 13, 2008 Share Posted June 13, 2008 Hey there, wondering if someone could give me a hand writing an SQL query... I have multiple tables that all have a field RequestId. What I would like to do is pull a list of Request Ids that were submitted on a specific date and then obtain the specifics of those requests from each of the several tables I have. So far I have been able to get the Request Ids submitted on specific dates with $startdate='06/03/2008'; $enddate='06/04/2008'; $SQLrequestID = "select RequestId From Request_Run WHERE TimeRunEnd BETWEEN '$startdate' AND '$enddate'"; $result_requestID = mssql_query($SQLrequestID); while ($IDs = mssql_fetch_array($result_requestID)) { echo $IDs['RequestId']."<br />"; } Now I want to take these Ids and for each id returned grab additional information such as all the info from table Request_Group, Request Measure and so on. And see it sorted by the Id. How do I make this second part happen? Link to comment https://forums.phpfreaks.com/topic/110117-sql-select-help-please/ Share on other sites More sharing options...
hitman6003 Posted June 19, 2008 Share Posted June 19, 2008 Use a JOIN query... SELECT Request_Group.group, Request_Measure.measurement FROM Request_Run RIGHT JOIN Request_Group ON Request_Run.RequestId = Request_Group.RequestId RIGHT JOIN Request_Measure ON Request_Run.RequestId = Request_Measure.RequestId WHERE Request_Run.TimeRunEnd BETWEEN '...' AND '...' ORDER BY Request_Run.RequestId Link to comment https://forums.phpfreaks.com/topic/110117-sql-select-help-please/#findComment-568699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.