Note that there are some explanatory texts on larger screens.

plurals
  1. POGet sql max datetime of multiple rows
    primarykey
    data
    text
    <p>This statement returns 2 rows:</p> <pre><code>SELECT ts.UnitId,ts.TeststepId, MAX(ts.CreatedAt)as CreatedAt FROM Teststep ts INNER JOIN Unit u ON ts.UnitId = u.UnitId Where u.TemplateId = 2 Group by TeststepId, ts.UnitId </code></pre> <p>How can I get the one row with the highest <code>CreatedAt</code> date ? Should I distinct the <code>unitId</code>?</p> <p><strong>UPDATE</strong></p> <p>Aaron and flem aksed for more info:</p> <pre><code>1 Template has N Units 1 Unit has N Teststeps </code></pre> <p>The clustered primary key of the Teststep table is TeststepId and CreatedAt. </p> <pre><code>[TeststepId] [int] NOT NULL, [Name] [nvarchar](50) NOT NULL, [PreCondition] [nvarchar](500) NOT NULL, [TestInstruction] [nvarchar](500) NOT NULL, [ExpectedResult] [nvarchar](500) NOT NULL, [CreatedAt] [datetime] NOT NULL, [CreatedBy] [nvarchar](50) NOT NULL, [UnitId] [int] NOT NULL, </code></pre> <p>The <strong>Teststep</strong> table</p> <p>sample data with the most important fields in the Teststep table could be:</p> <p><img src="https://i.stack.imgur.com/9OCUp.png" alt="enter image description here"></p> <p>The teststep shows historized teststeps. From the above image you see that the TeststepId = 4 exist 2 times. A historized version (58 sec.) and a current version (59 sec.).</p> <p>I want to get only the teststepid 4 with 59 seconds to show in a "current" View.</p> <p><strong>UPDATE 2</strong></p> <p>I want to get only the teststepid 4 with 59 seconds AND all other teststepId<code>s with their current date. If there are only rows with different teststepid</code>s take those because they are the current rows.</p> <p>I am just about to change my integration test and find about the solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload