Skip to content

Tag: sql-order-by

Select the row with the most recent modified date

I have this table: user_id name email modified_date 1 John 2022-01-01 1 John 2022-01-02 1 Lucy 2022-01-03 2 Joey 2021-12-24 3 Mike 2022-01-01 3 Mary 2022-01-02 I’m trying to get unique user_id’s email with the most recent modified_date. This is my expected output: user_id email name 1 Lucy 2 Joey 3

SQL query for entries of last N jobs

I have the following table: etc, so basically jobs keep adding entries concurrently I am looking for an efficient query to return all entries of the latest (by time) N jobs So find the first (by time) entry for each job, then using that get the latest N jobs with all their entries So for the above table and N=3