user1809407
user1809407

Reputation:

Select value in Oracle

I have this Oracle SQL query which I use to make checks for number:

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID = ?

I want to select all values different than the value 12. How I must edit the query?

Upvotes: 1

Views: 119

Answers (3)

A B
A B

Reputation: 4148

Are you trying to return values that are not set at all?

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID != 12

Will only return values that have MSYSTEMGROUPID set to a value.

If you want Both values not equal to 12 and values that are not set at all, use this:

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID  IS NULL OR MSYSTEMGROUPID != 12

Upvotes: 1

Mike Christensen
Mike Christensen

Reputation: 91598

There are two not equals operators in Oracle. The <> operator, which is the ANSI SQL standard, and the != operator, which is supported by most if not all relational databases. Conceptually, they should provide the same results, however according to this post, they might result in different execution plans affecting performance.

Your query can be expressed as:

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID != 12

or:

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID <> 12

You could also use the NOT IN operator if you wanted to support multiple values. If you wanted to exclude 12, 15 and 20, you could do:

SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID NOT IN (12, 15, 20)

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172418

Try this:-

 SELECT * from MANAGEDSYSTEMGROUPS where MSYSTEMGROUPID != 12

Upvotes: 0

Related Questions