From 7d96952e68dfab55c99048fa23cbb8b41139625f Mon Sep 17 00:00:00 2001 From: Zack T Date: Thu, 4 Jul 2024 16:23:04 -0700 Subject: [PATCH] Adding new query to find devices with multiple attachments --- .../Queries-Miscellaneous.sql | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/Jamf Pro/Reporting/Database Maintenance and SQL Queries/Queries-Miscellaneous.sql b/Jamf Pro/Reporting/Database Maintenance and SQL Queries/Queries-Miscellaneous.sql index 9ade002..5479088 100644 --- a/Jamf Pro/Reporting/Database Maintenance and SQL Queries/Queries-Miscellaneous.sql +++ b/Jamf Pro/Reporting/Database Maintenance and SQL Queries/Queries-Miscellaneous.sql @@ -19,7 +19,7 @@ SELECT FROM information_schema.tables WHERE table_schema = "jamfsoftware" - and Round(( ( data_length + index_length ) / 1024 / 1024 ), 2) > 500 + AND Round(( ( data_length + index_length ) / 1024 / 1024 ), 2) > 500 ORDER BY 3 DESC; @@ -224,12 +224,42 @@ WHERE ; +-- ################################################## +-- Get devices with multiple attachments +SELECT + object_id AS "JSS ID", + object_type AS "Device Type", + attachments.attachment_id AS "Attachment ID", + filename AS "Filename", + file_type AS "File Type", + file_size AS "File Size" +FROM attachments +LEFT OUTER JOIN attachment_assignments + ON attachment_assignments.attachment_id = attachments.attachment_id +WHERE + -- Optionally limit by file type + -- file_type IN ( "application/zip", "application/octet-stream" ) + -- AND + attachments.attachment_id IN ( + SELECT attachment_id + FROM attachment_assignments + WHERE object_id IN ( + SELECT object_id + FROM attachment_assignments + GROUP BY object_id, object_type + HAVING COUNT(object_id) > 1 + ) +) +ORDER BY object_id +; + + -- ################################################## -- Get where a script is used -select policy_id -from policy_scripts -where script_id = ( - select scripts.script_id - from scripts - where scripts.file_name = "" +SELECT policy_id +FROM policy_scripts +WHERE script_id = ( + SELECT scripts.script_id + FROM scripts + WHERE scripts.file_name = "" );