r/SQL • u/insufficient_funds • Jun 11 '26
Discussion [MSSQL / SWQL] Need help modifying my query to only show unique entries from one column
This is using Solarwinds implementation of SQL, which from what I've seen, seems to share an extreme majority of stuff with MSSQL, but adds some of their own weirdness.
I have a query in my Solarwinds environment that is currently functioning, though I've realized the 'Distinct' thing applies to the whole row, not an individual column.
I'm trying to find a way to make the result only show one entry for each unique name from the field Nodes.Caption
I'm honestly way over my depth on this, this query is kinda strung together from other things I've found online...
select DISTINCT
Nodes.caption as [Device],
ToLocal(Alerts.SuppressFrom) as [Mute From],
ToLocal(Alerts.SuppressUntil) as [Mute Until],
SEA.ScheduleTask.Reason,
SUBSTRING(SEA.ScheduleTask.AccountID, 0, CHARINDEX('@',SEA.ScheduleTask.AccountID)) as [Muted By]
from Orion.AlertSuppression Alerts
LEFT join Orion.nodes Nodes on Alerts.EntityURI = Nodes.uri
LEFT Join Orion.ScheduleEntityAssignment SEA ON Alerts.EntityUri = SEA.EntityURI
where ToLocal(Alerts.SuppressUntil) > GetDate()
order by Nodes.caption ASC
Here's what the output currently looks like:
Nodes with Muted Alerts
| Device | Mute From | Mute Until | Reason | Muted By |
|---|---|---|---|---|
| Server1 | 6/11/2026 8:35:40 AM | 12/31/9998 9:00:00 PM | insufficient_Funds | |
| Server1 | 6/11/2026 8:35:40 AM | 12/31/9998 9:00:00 PM | Decommissioning | insufficient_Funds |
| Server2 | 6/9/2026 4:17:38 PM | 12/31/9998 9:00:00 PM | insufficient_Funds | |
| Server2 | 6/9/2026 4:17:38 PM | 12/31/9998 9:00:00 PM | Decommissioning | insufficient_Funds |
I'm trying to only show one entry for each Device name (nodes.caption) despite there sometimes being multiple.
Thank you anyone for assistance.
3
u/GRRRRRRRRRRRRRG Jun 11 '26
You need to clarify what record you want in your result. You need one row per Nodes.Caption. But what about all other fields, do you need any order applied to them, do you need them at all...
1
u/Rumborack17 Jun 11 '26
You are looking for group by. You should google it if you want to understand it better. I will keep it very simple assuming you only want to solve this one issue.
Basically you group the data by a column (or multiple columns), this allows you to get information about multiple entries in a single line (e.g. with count() you could display the number of times each group appears).
You do lose some "flexebility" tho, as you cannot directly use columns if they are not in your "group by". You need to use aggregation functions for those (max, min, avg, sum, etc.).
Depending on what exactly you want to "know" from this query, it will look different.
I make 2 assumtions about your logic:
- The "mute from" is irrelevant, as there is no option to make mutes into the future in your system and therefore the highest "mute until" + the server is all you really care about.
- the Reason and muted by are not important, otherwise again a group by will not be usefull here
If that is not the case you will need some more fancy adaptations, if you really only want one line per server. But heavily depends on what exaclty you want to "know" from this query.
You could get the other things with aggregation functions as well, but I assume they dont really server a purpose, otherwise you would want to go for more than 1 line per server.
I assume your dialect works exactly like T-SQL here, as i never worked with SWQL.