Solved

SQL Minus Query

Posted on 2004-09-20
10
11,007 Views
Last Modified: 2012-08-13
I am looking for a solution that would be similar to Oracle's minus query.  I have two tables, an employee table and an employee_skill table.  I need a query that will pull out all employees that do not have a certain skill.

example:  Select * from employee, employee_skill
               where employee.empid = employee_skill.empid

               MINUS
 
               Select * from employee, employee_skill
               where employee.empid = employee_skill.empid
               and skill_id = 2 //or whatever skill#
             
0
Comment
Question by:d_vonfeldt
  • 4
  • 4
  • 2
10 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 12106204
Select * from employee, employee_skill inner join employee.empid = employee_skill.empid where employee_skill <> 2;
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 200 total points
ID: 12106282
SELECT * FROM employee WHERE empid NOT IN (SELECT empid FROM employee_skill As A WHERE A.skill_id=2 AND A.empid=employee.empid)
0
 

Author Comment

by:d_vonfeldt
ID: 12106284
Select * from employee, employee_skill inner join employee.empid = employee_skill.empid where employee_skill <> 2;

that line of code gave me a syntax error in FROM clause message.

Is that line equivalent to: Select * from employee, employee_skill
                                    where employee.empid = employee_skill.empid
                                    and skill_id <> 2.

I am not too familiar with inner joins?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:d_vonfeldt
ID: 12106353
Thanks,

That was quick and easy.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 12106412
Sorry, I got it wrong. For the record, I think it should be:

Select * from employee inner join employee.empid = employee_skill.empid where employee_skill <> 2;
0
 
LVL 44

Expert Comment

by:GRayL
ID: 12106424
Still got it wrong:

Select * from employee inner join employee.empid = employee_skill.empid where employee_skill.skill_id <> 2;
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12106476
GRayL, you have not specified the join table in your query. It should read (modifications in caps):

Select EMPLOYEE.* from employee inner join EMPLOYEE_SKILL ON employee.empid = employee_skill.empid where employee_skill.skill_id <> 2;

However, this only returns records where the skill_id is not 2 - if an employee has skill 2, it simply doesn't include that record in the list, but includes all of his other skill records. It doesn't return records for employees who don't have skill 2 at all.
0
 

Author Comment

by:d_vonfeldt
ID: 12106489
I am still getting the same error when using

Select * from employee inner join employee.empid = employee_skill.empid where employee_skill.skill_id <> 2;
0
 

Author Comment

by:d_vonfeldt
ID: 12106513
perfect explanation shanesuebsahkarn,  that is what was giving me the troubles.

0
 
LVL 44

Expert Comment

by:GRayL
ID: 12106666
Nicely done Shane.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

777 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