Jump to content

SQL Select Help Please


mATOK

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

        $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
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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.