Solved

Set notation vs SQL

Posted on 2011-09-14
2
375 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
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 59

Accepted Solution

by:
Kevin Cross earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

932 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now