Skip to content

Instantly share code, notes, and snippets.

@glesica
Created November 11, 2011 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glesica/1356974 to your computer and use it in GitHub Desktop.
Save glesica/1356974 to your computer and use it in GitHub Desktop.
mysql> SELECT c.computer_name, a.application_name, a.application_version, i.audit_date FROM installations i INNER JOIN computers c ON i.computer_id=c.computer_id INNER JOIN applications a ON i.application_id=a.application_id WHERE c.computer_name="computer01" ORDER BY c.computer_name, a.application_name, i.audit_date;
+---------------+-----------------------+---------------------+------------+
| computer_name | application_name | application_version | audit_date |
+---------------+-----------------------+---------------------+------------+
| computer01 | Adobe Acrobat Reader | 8.1.4 | 2011-11-09 |
| computer01 | Adobe Acrobat Reader | 8.1.4 | 2011-11-10 |
| computer01 | Microsoft Office 2007 | 12.0.1 | 2011-11-09 |
| computer01 | Microsoft Office 2007 | 12.0.1 | 2011-11-10 |
| computer01 | Mozilla Firefox | 5.0 | 2011-11-09 |
| computer01 | Mozilla Firefox | 7.0 | 2011-11-10 |
+---------------+-----------------------+---------------------+------------+
6 rows in set (0.01 sec)
mysql> SELECT
-> c.computer_name
-> , a.application_name
-> , a.application_version
-> , i.audit_date
-> FROM installations i
-> INNER JOIN computers c
-> ON i.computer_id = c.computer_id
-> INNER JOIN applications a
-> ON i.application_id = a.application_id
-> WHERE c.computer_name = "computer01"
-> GROUP BY c.computer_name, a.application_name, a.application_version
-> HAVING i.audit_date = MAX(i.audit_date)
-> ORDER BY c.computer_name, a.application_name, i.audit_date;
+---------------+-----------------------+---------------------+------------+
| computer_name | application_name | application_version | audit_date |
+---------------+-----------------------+---------------------+------------+
| computer01 | Adobe Acrobat Reader | 8.1.4 | 2011-11-10 |
| computer01 | Microsoft Office 2007 | 12.0.1 | 2011-11-10 |
| computer01 | Mozilla Firefox | 5.0 | 2011-11-09 |
| computer01 | Mozilla Firefox | 7.0 | 2011-11-10 |
+---------------+-----------------------+---------------------+------------+
4 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment