Combine two queries to create one query with one result set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • csolomon
    New Member
    • Mar 2008
    • 166

    Combine two queries to create one query with one result set

    Hello:

    I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them combined.

    **Max Date/Time Query-Finds the most recent updated record based on the time and date (Correct Results Returned)
    SELECT [Yard Panel Number].panelNumber, Max([Yard Location].locDate) AS MaxOflocDate, Max([Yard Location].completionTime ) AS MaxOfcompletion Time, [Yard Panel Number].jobNumber, [Yard Location].panelID
    FROM [Yard Panel Number], [Yard Location]
    WHERE ((([Yard Panel Number].panelID)=[Yard Location].[panelID]))
    GROUP BY [Yard Panel Number].panelNumber, [Yard Panel Number].jobNumber, [Yard Location].panelID
    ORDER BY [Yard Panel Number].panelNumber;

    **From To Query--Finds all record locations (Correct Results Returned)
    SELECT [Project Information].jobName, [Project Information].jobNumber, [Yard Location].locationFrom, [Yard Location].locationTo, [Yard Location].panelID, [Yard Location].damage
    FROM [Project Information], [Yard Location]
    WHERE ((([Project Information].[jobNumber])=[Yard Location].[jobNumber]));

    **Finally, Query1--Combines above queries, to find the most recent record of locations, based on the most recent date and time. When I run this query I return NO results
    SELECT DISTINCT [FromTo Query].jobName, [FromTo Query].jobNumber, [Max Date/Time Query].panelNumber, [Max Date/Time Query].MaxOflocDate, [Max Date/Time Query].MaxOfcompletio nTime, [FromTo Query].locationFrom, [FromTo Query].locationTo
    FROM [Max Date/Time Query], [FromTo Query]
    WHERE ((([FromTo Query].[paneID])=[Max Date/Time Query].[panelID]))
    AND ((([FromTo Query].[jobNumber])=[Max Date/Time Query].[jobNumber]));

    I can't figure it out, Please advise!

    Any assistance is appreciated.
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    Originally posted by csolomon
    Hello:

    I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them combined.

    **Max Date/Time Query-Finds the most recent updated record based on the time and date (Correct Results Returned)
    SELECT [Yard Panel Number].panelNumber, Max([Yard Location].locDate) AS MaxOflocDate, Max([Yard Location].completionTime ) AS MaxOfcompletion Time, [Yard Panel Number].jobNumber, [Yard Location].panelID
    FROM [Yard Panel Number], [Yard Location]
    WHERE ((([Yard Panel Number].panelID)=[Yard Location].[panelID]))
    GROUP BY [Yard Panel Number].panelNumber, [Yard Panel Number].jobNumber, [Yard Location].panelID
    ORDER BY [Yard Panel Number].panelNumber;

    **From To Query--Finds all record locations (Correct Results Returned)
    SELECT [Project Information].jobName, [Project Information].jobNumber, [Yard Location].locationFrom, [Yard Location].locationTo, [Yard Location].panelID, [Yard Location].damage
    FROM [Project Information], [Yard Location]
    WHERE ((([Project Information].[jobNumber])=[Yard Location].[jobNumber]));

    **Finally, Query1--Combines above queries, to find the most recent record of locations, based on the most recent date and time. When I run this query I return NO results
    SELECT DISTINCT [FromTo Query].jobName, [FromTo Query].jobNumber, [Max Date/Time Query].panelNumber, [Max Date/Time Query].MaxOflocDate, [Max Date/Time Query].MaxOfcompletio nTime, [FromTo Query].locationFrom, [FromTo Query].locationTo
    FROM [Max Date/Time Query], [FromTo Query]
    WHERE ((([FromTo Query].[paneID])=[Max Date/Time Query].[panelID]))
    AND ((([FromTo Query].[jobNumber])=[Max Date/Time Query].[jobNumber]));

    I can't figure it out, Please advise!

    Any assistance is appreciated.
    Can you include some data samples returned from each query and what is in the tables also

    and you may also include the result that you're looking for visually speaking.

    Thanks,

    Joe P.

    Comment

    Working...