Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL problem

SQL problem

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Deem
    wrote on last edited by
    #1

    Hi, I have a table consisting of an ID, a Date and a StatusCode. Basically it holds a log of when the status of things ('Defects') identified by the ID changed. (The ID is NOT unique in this table). I am trying to develop an SQL statement that will return the ID and Date for records that have most recently been changed to a certain status. I am using MS Access. The Query below will return the date that each Defect's status was last changed: SELECT DefectNumber, Max(DateTime) FROM MAIN_Status GROUP BY DefectNumber I want to be able to discard records from the results of this that are not currently "issued". NOTE: Using a WHERE StatusCode = "ISS" clause does not do what is required - it will give me the most recent date that each Defect has been issued. After a defect has been issued it can then be changed to completed and thus is no longer relevant. I hope this makes sense... Any suggestions at all would be great. Thanks, Alex

    M 1 Reply Last reply
    0
    • A Alex Deem

      Hi, I have a table consisting of an ID, a Date and a StatusCode. Basically it holds a log of when the status of things ('Defects') identified by the ID changed. (The ID is NOT unique in this table). I am trying to develop an SQL statement that will return the ID and Date for records that have most recently been changed to a certain status. I am using MS Access. The Query below will return the date that each Defect's status was last changed: SELECT DefectNumber, Max(DateTime) FROM MAIN_Status GROUP BY DefectNumber I want to be able to discard records from the results of this that are not currently "issued". NOTE: Using a WHERE StatusCode = "ISS" clause does not do what is required - it will give me the most recent date that each Defect has been issued. After a defect has been issued it can then be changed to completed and thus is no longer relevant. I hope this makes sense... Any suggestions at all would be great. Thanks, Alex

      M Offline
      M Offline
      Matt Gullett
      wrote on last edited by
      #2

      If I understand what you are asking, I think what you need to do is have a WHERE clause with an IN statement SELECT DefectNumber, Max(DateTime) FROM MAIN_Status WHERE ID not IN (SELECT ID FROM MAIN_Status where sts = 'completed) GROUP BY DefectNumber

      A 1 Reply Last reply
      0
      • M Matt Gullett

        If I understand what you are asking, I think what you need to do is have a WHERE clause with an IN statement SELECT DefectNumber, Max(DateTime) FROM MAIN_Status WHERE ID not IN (SELECT ID FROM MAIN_Status where sts = 'completed) GROUP BY DefectNumber

        A Offline
        A Offline
        Alex Deem
        wrote on last edited by
        #3

        Would this not just retrieve the Date for when each defect was last issued? What I require is a list of defects for which the last action was to issue them, and i require the Date at which this took place. I imagine this is hard to understand without a more verbose description of the problem. Perhaps explaining an analogous situation could help: A table of employee details as follows: DepartmentCode Name Salary 1 Alex 40000 1 Kevin 30000 1 Mark 20000 2 Bruce 50000 2 John 60000 3 Michael 70000 Say I want to find the employees in each Department with the highest salary. I could do: SELECT DepartmentCode, MAX(Salary) FROM employees GROUP BY DepartmentCode to get a table with DepartmentCode and Salary, but how can i also get the Name of the highest paid person? The Name is analogous to my StatusCode, if i can get the StatusCode in the results i can use perhaps a HAVING clause to eliminate the ones that are not "ISS". I hope this makes things clearer Thanks for your help :) ~Alex

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups