[SOLVED] Duplicate SQL query for host

Share your SQL query ideas for reporting in the WAPT Enterprise console here
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
User avatar
Gaetan
Messages: 169
Registration: August 8, 2019 - 10:16
Location: Toulouse

October 18, 2023 - 5:25 PM

Good morning,

Here is a query that retrieves duplicate posts on a park:

Code: Select all

SELECT count(hosts.computer_name) AS count_double,hosts.computer_name
from hosts
group by hosts.computer_name
having count(hosts.computer_name) > 1
User avatar
Gaetan
Messages: 169
Registration: August 8, 2019 - 10:16
Location: Toulouse

June 20, 2024 - 10:29

Improvement for displaying it in inventory filters:

Code: Select all

SELECT h.uuid, h.computer_name
FROM hosts h
JOIN (
    SELECT computer_name
    FROM hosts
    GROUP BY computer_name
    HAVING COUNT(computer_name) > 1
) dup ON h.computer_name = dup.computer_name
ORDER BY h.uuid;
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

July 13, 2024 - 08:10

Hello,
thank you for the request! Could you remind me how to add this query to the "Filter with queries" search field in the console? I knew how, but I can't find the information anymore... And as I recall, it wasn't intuitive at all.
User avatar
Gaetan
Messages: 169
Registration: August 8, 2019 - 10:16
Location: Toulouse

July 15, 2024 - 09:25

Hello, when you put the UUID in your query it appears :)
jarnaud
Messages: 16
Registration: May 3, 2024 - 3:37 p.m.

October 9, 2025 - 4:36 PM

Hello,

We have taken the time to document the method in the official documentation:
https://www.wapt.fr/fr/doc/wapt-console ... entory-tab

Have a good day
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

November 7, 2025 - 10:32

Code: Select all

WITH x AS (
  SELECT
    uuid,
    computer_name,
    last_seen_on,
    COUNT(*) OVER (PARTITION BY computer_name) AS cnt,
    MAX(last_seen_on) OVER (PARTITION BY computer_name) AS last_seen_max
  FROM hosts
)
SELECT uuid, computer_name, last_seen_on
FROM x
WHERE cnt > 1
  AND last_seen_on < last_seen_max 
ORDER BY computer_name, last_seen_on;
Locked