code logs -> 2024 -> Thu, 18 Jan 2024< code.20240117.log - code.20240119.log >
--- Log opened Thu Jan 18 00:00:46 2024
01:17 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has quit [Connection closed]
02:00 Degi [Degi@Nightstar-rlg593.pool.telefonica.de] has quit [Ping timeout: 121 seconds]
02:02 Degi [Degi@Nightstar-j86j8c.pool.telefonica.de] has joined #code
02:04 ErikMesoy [Bruker@Nightstar-u36.h65.232.178.IP] has joined #code
02:04 ErikMesoy1 [Bruker@Nightstar-u36.h65.232.178.IP] has quit [Ping timeout: 121 seconds]
04:59 craftxbox [craftxbox@Nightstar-dltca9.ninja] has joined #code
08:42 JustBob [justbob@Nightstar.Customer.Dissatisfaction.Administrator] has quit [NickServ (RECOVER command used by JustLurk)]
08:42 JustBob [justbob@Nightstar.Customer.Dissatisfaction.Administrator] has joined #code
08:42 mode/#code [+o JustBob] by ChanServ
14:52 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has joined #code
14:52 mode/#code [+qo Vornicus Vornicus] by ChanServ
15:41 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has quit [Connection closed]
16:37 mode/#code [+o ErikMesoy] by ChanServ
17:00 Emmy [Emmy@Nightstar-qo29c7.fixed.kpn.net] has joined #code
19:53
<@macdjord>
SQL question: I have a table 'scans' with columns (machine_id, timestamp, user, result). I wish to find, with a single query, when the last scan was done for each machine and which user did the scan. How should I structure my query to do this?
19:54
<@macdjord>
I know I can do `SELECT machine_id, max(timestamp) FROM scans GROUP BY machine_id;` to get the timestamp of the latest scan for each machine, but how do I also get the user who performed that scan?
19:59
<@macdjord>
I can think of one way - use a subquery to get the machine ID and timestamp-of-latest-scan, concatenate them together, then use a `WHERE ... IN` clause on the main query to select the corresponding rows, and get the desired columns as normal. But that seems really awkward and inefficient.
20:01
<@macdjord>
Something like this, except there'd probably need to be a bunch of typecasting to make the concatenation work: SELECT machine_id, timestamp, user FROM scans WHERE CONCAT(machine_id, max(timestamp)) in (SELECT CONCAT(machine_id, max(timestamp)) FROM scans GROUP BY machine_id`);
20:15 Syloq [Syloq@NetworkAdministrator.Nightstar.Net] has quit [[NS] Quit: .]
20:18 Syloq [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code
20:18 mode/#code [+o Syloq] by ChanServ
22:40 Emmy [Emmy@Nightstar-qo29c7.fixed.kpn.net] has quit [Ping timeout: 121 seconds]
--- Log closed Fri Jan 19 00:00:47 2024
code logs -> 2024 -> Thu, 18 Jan 2024< code.20240117.log - code.20240119.log >

[ Latest log file ]