Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:18:07+00:00 2026-05-31T03:18:07+00:00

I am trying query for the most recent scan date (the two most recent

  • 0

I am trying query for the most recent scan date (the two most recent ones are 3/5/2012 and 3/1/2012 … I’d like to only return records from 3/5/2012, but I need this to be automated so every time a new scan is run the query is only pulling the most recent date.

I’m also joining the two tables by IP. I put together the query below and am receiving the error “Please check the SQL syntax. Column qryReportsCondensedPatchesAggregate.ScanName is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.”

SELECT qryReportsCondensedPatchesAggregate.ScanName,
    qryReportsCondensedPatchesAggregate.pspplMSSeverity,
    qryReportsCondensedPatchesAggregate.smachIPAddress,
    qryReportsScanSummaryWithDetailsAggregate.PatchMissing, 
    MAX(qryReportsCondensedPatchesAggregate.ScanDate)
FROM qryReportsCondensedPatchesAggregate
INNER JOIN qryReportsScanSummaryWithDetailsAggregate
ON qryReportsCondensedPatchesAggregate.smachIPAddress=qryReportsScanSummaryWithDetailsAggregate.smachIPAddress
WHERE qryReportsCondensedPatchesAggregate.ScanName LIKE '%mgmt%' 
    AND qryReportsCondensedPatchesAggregate.ScanDate>= dateadd(day,-30,getdate())
ORDER BY qryReportsCondensedPatchesAggregate.ScanDate DESC

Edit: Here is some sample data of what is being returned:

Column1 smachIPAddress   ScanName   pspplMSSeverity PatchMissing

3/5/2012 15:24  162.1.1.1   Mgmt Servers OU 0   1
3/5/2012 15:24  162.1.1.1   Mgmt Servers OU 0   1
3/5/2012 15:24  1162.1.1.1  Mgmt Servers OU 0   1
3/5/2012 15:24  162.1.1.1   Mgmt Servers OU 0   2
3/5/2012 15:24  162.1.1.1   Mgmt Servers OU 0   1
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   2
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   4
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   2
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   3
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   1
3/1/2012 17:29  162.1.1.1   Mgmt Servers OU 0   3

First table:

table_name  ordinal_position    column_name data_type   is_nullable character_maximum_length
qryReportsCondensedPatchesAggregate 1   MachineGroup    nvarchar    YES 276
qryReportsCondensedPatchesAggregate 2   ScanID  int NO  
qryReportsCondensedPatchesAggregate 3   ScanUser    nvarchar    YES 4000
qryReportsCondensedPatchesAggregate 4   ScanDate    datetime    NO  
qryReportsCondensedPatchesAggregate 5   ScanName    nvarchar    YES 255
qryReportsCondensedPatchesAggregate 6   itemType    int YES 
qryReportsCondensedPatchesAggregate 7   smachID int NO  
qryReportsCondensedPatchesAggregate 8   smachName   nvarchar    NO  255
qryReportsCondensedPatchesAggregate 9   smachIPAddress  nvarchar    YES 39
qryReportsCondensedPatchesAggregate 10  smachDomainName nvarchar    YES 255
qryReportsCondensedPatchesAggregate 11  smachIPDecimal  float   YES 
qryReportsCondensedPatchesAggregate 12  smachAnnotation ntext   YES 1073741823
qryReportsCondensedPatchesAggregate 13  smachNotFoundReasonErrorNum smallint    YES 
qryReportsCondensedPatchesAggregate 14  smachServerType int YES 
qryReportsCondensedPatchesAggregate 15  mmOSID  int YES 
qryReportsCondensedPatchesAggregate 16  patchBulletinID nvarchar    NO  255
qryReportsCondensedPatchesAggregate 17  patchBulletinURL    nvarchar    YES 4000
qryReportsCondensedPatchesAggregate 18  patchQNumbers   nvarchar    NO  255
qryReportsCondensedPatchesAggregate 19  patchLevel  int YES 
qryReportsCondensedPatchesAggregate 20  pspplMSSeverity int YES 
qryReportsCondensedPatchesAggregate 21  pspplCriticality    int YES 
qryReportsCondensedPatchesAggregate 22  pspplAnnotation nvarchar    YES 4000
qryReportsCondensedPatchesAggregate 23  prodID  int NO  
qryReportsCondensedPatchesAggregate 24  spplspID    int NO  
qryReportsCondensedPatchesAggregate 25  scanType    int YES

2nd table:

table_name  ordinal_position    column_name data_type   is_nullable character_maximum_length
qryReportsScanSummaryWithDetailsAggregate   1   ScanID  int NO  
qryReportsScanSummaryWithDetailsAggregate   2   scanType    int YES 
qryReportsScanSummaryWithDetailsAggregate   3   ScanName    nvarchar    YES 255
qryReportsScanSummaryWithDetailsAggregate   4   ScanDate    datetime    NO  
qryReportsScanSummaryWithDetailsAggregate   5   ScanUser    nvarchar    YES 4000
qryReportsScanSummaryWithDetailsAggregate   6   consoleID   int YES 
qryReportsScanSummaryWithDetailsAggregate   7   consoleName nvarchar    YES 255
qryReportsScanSummaryWithDetailsAggregate   8   smachName   nvarchar    NO  255
qryReportsScanSummaryWithDetailsAggregate   9   smachIPAddress  nvarchar    YES 39
qryReportsScanSummaryWithDetailsAggregate   10  scantName   nvarchar    YES 255
qryReportsScanSummaryWithDetailsAggregate   11  FirstPatchGroupName nvarchar    YES 255
qryReportsScanSummaryWithDetailsAggregate   12  CountPatchGroups    int YES 
qryReportsScanSummaryWithDetailsAggregate   13  smachAgent  smallint    NO  
qryReportsScanSummaryWithDetailsAggregate   14  smachDomainName nvarchar    YES 255
qryReportsScanSummaryWithDetailsAggregate   15  smachIPDecimal  float   YES 
qryReportsScanSummaryWithDetailsAggregate   16  smachID int NO  
qryReportsScanSummaryWithDetailsAggregate   17  smachListType   int YES 
qryReportsScanSummaryWithDetailsAggregate   18  ScanXMLVersion  nvarchar    YES 50
qryReportsScanSummaryWithDetailsAggregate   19  ScanXMLDate datetime    YES 
qryReportsScanSummaryWithDetailsAggregate   20  itemLanguageID  nvarchar    YES 4
qryReportsScanSummaryWithDetailsAggregate   21  PatchFoundOrInstalled   int YES 
qryReportsScanSummaryWithDetailsAggregate   22  PatchMissing    int YES 
qryReportsScanSummaryWithDetailsAggregate   23  ServicePackMissing  int YES 
qryReportsScanSummaryWithDetailsAggregate   24  CountofMachinesScanned  int NO  
qryReportsScanSummaryWithDetailsAggregate   25  CountofMachinesNotScanned   int NO  
qryReportsScanSummaryWithDetailsAggregate   26  TotalMachines   int YES 
qryReportsScanSummaryWithDetailsAggregate   27  ScanFoundPatches    int YES 
qryReportsScanSummaryWithDetailsAggregate   28  ScanMissingPatches  int YES 
qryReportsScanSummaryWithDetailsAggregate   29  ScanServicePackMissing  int YES 
qryReportsScanSummaryWithDetailsAggregate   30  CountOfGroups   int YES 
qryReportsScanSummaryWithDetailsAggregate   31  grpName nvarchar    YES 255
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:18:08+00:00Added an answer on May 31, 2026 at 3:18 am

    Your error is telling you the problem, if you are using an Aggregate function MAX(), SUM(), etc the fields not using the Aggregate must be included in a GROUP BY.

    Below is what your query looks like with aliases and a GROUP BY

    SELECT CPA.ScanName,
        CPA.pspplMSSeverity,
        CPA.smachIPAddress,
        SDA.PatchMissing, 
        MAX(CPA.ScanDate)
    FROM qryReportsCondensedPatchesAggregate CPA
    INNER JOIN qryReportsScanSummaryWithDetailsAggregate SDA
        ON CPA.smachIPAddress=SDA.smachIPAddress
    WHERE CPA.ScanName LIKE '%mgmt%' 
        AND CPA.ScanDate>= dateadd(day,-30,getdate())
    GROUP BY CPA.ScanName, CPA.pspplMSSeverity, CPA.smachIPAddress
        , SDA.PatchMissing, CPA.ScanDate
    ORDER BY CPA.ScanDate DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a query that will return only the most recent
I'm trying to write a query that will pull back the two most recent
I am trying to find the most injured player from my query but I
I'm trying to write a query that returns the most recent GPS positions from
I have two tables that I am trying to join in a query, but
I'm trying to get the ip, user, and most recent timestamp from a table
I am trying to get the most recent data item from the datastore. I
Before trying to query the AD server I would like to check if it
I'm trying to query a MySQL database using an array but I'm having trouble!
I'm trying to query records in Google App engine where an IntegerProperty is null

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.