Jump to content

SQL Select Help Please


Recommended Posts

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

        $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
Share on other sites

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
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.