Select Statement Question- Using Minus or Except

pts.
Tags:
SQL
A table has the following columns and values Plant, Empname, Post,Salary (Det,Jade,Manager,3000) (Tex,Jack,Manager,5000) (Mia,Marr,Analyst,2040) (Det,John,Sr Analyst,1500) (Tex,Jamie,Sr Analyst,5000) (Mia,Erin,Analyst,2040) (Det,Carl,Analyst,1500) I have to write a select statement which returns only those rows where plant is not equal to 'Det' if Post is 'Manager' Is it posible to write a single select without using Minus or Except. I got the required results by writing the following select statement. Select Plant,EmpName,Post,Salary from table Minus select Plant,Empname,Post,Salary from table where Plant = 'Det' and Post='Manager" Is it possible get the results without using the Minus. Thanks in advance.

Answer Wiki

Thanks. We'll let you know when a new response is added.

If I understand your request, you want everyone except the Detroit managers. If so, the SQL would use not (! in Oracle SQL) as follows:

Select Plant,EmpName,Post,Salary
from table
where ! (Plant = ‘Det’ and Post = ‘Manager’)

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Mcp111
    select Plant,Empname,Post,Salary from table where Plant 'Det' and Post='Manager'
    0 pointsBadges:
    report
  • Kmarur
    Thanks for the quick response, but niether statements are working for me. MCP111 - The select statement that you gave returns only one row (Tex,Jack,Manager,3000) But I want all rows except for Detroit Managers as stevewaltz mentioned. stevewaltz - I ran your select statement and got the following error --3:20:51 PM ORA-00936: missing expression-- where could I be wrong.
    0 pointsBadges:
    report
  • Stevewaltz
    Sorry about that. The exclamation point works with =, but not with expressions. Try it with the word not instead of the exclamation point.
    0 pointsBadges:
    report
  • Kmarur
    GREAT!! Thank you Using the word NOT worked perfectly. Thanks again.
    0 pointsBadges:
    report
  • Jwhanon
    If I understand what you're asking, it's simple: select Plant,Empname,Post,Salary from table where Plant != 'Det' and Post != 'Manager'
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following