[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Set notation vs SQL

Posted on 2011-09-14
2
Medium Priority
?
390 Views
Last Modified: 2012-06-21
Scenario: In my organisation I want to identify the PCs having only authorised software installed.

To do this I could compare the applications installed on each PC with my list of authorised applications.  Using set theory / notation the solution is easy to express i.e. a PC is considered authorised if its applications are a subset of the authorised list.
What I’m trying to get my head around is how this ‘solution’ could be implemented using SQL? I’m after some sound pointers or approaches.
Thanks.
0
Comment
Question by:antonms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36536965
Instead of looking at the PCs that only have authorized software installed, you could exclude the PCs that do not have authorized software installed.  That would be an easier query to write.

Greg



0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36536969
antonms,

The principal is the same. Another way to look at this under set theory / notation is that no member of the PC's set of applications is outside the set of authorised ones.

Therefore, in SQL you can use EXISTS and NOT EXISTS to your favor. Basically, you can query for the rows where there does not exist another row for the same PC that has an application not listed on the authorised list, i.e., an application that does not match to a row in your authorised applications table.

In general terms:

SELECT {column list}
FROM A a1
WHERE NOT EXISTS (
   SELECT 1
   FROM A a2
   LEFT OUTER JOIN B b1 ON a2.AppID = b1.AppID
   WHERE a2.PcID = a1.PcID AND b1.AppID IS NULL
)

You can do the second piece with a NOT EXISTS as well, but wanted to show OUTER JOIN is also an option. But with NOT exists, you can find the PCs that have an invalid app but finding that the app does not exist in the authorised apps table. Then to find PCs with only authorised apps, you check for the inverse of that list. So top level could also use NOT IN if you replace SELECT 1 with SELECT PcID and remove filter on PcID in the inner queries WHERE clause.

Hopefully that isn't too convoluted an explanation and everything makes sense.

Kevin
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question