Any Operator in SQL Server with Example

  Total Views : 462
  Comments : 0
 
  Keywords : SQL any operator with example, Any operator example in sql server, Any operator in sql with example, Different examples to use any operator in sql server

Here we will learn what is any operator in sql server, use of any operator in sql server with example.

SQL Any Operator

The Any operator in SQL returns true when value matches with any value in single column set of values. It’s like OR operator it will compare value against with any value in column.

 

To check any operator in sql with example run following script to create tables

 

create table example1(id int, name varchar(50))

insert into example1 values(1,'suresh'),(2,'dasari'),(3,'rohini'),(4,'madhav'),(5,'honey')

create table example2(id int, name varchar(50))

insert into example2 values(1,'suresh'),(4,'madhav'),(5,'honey')

 

select * from example1

select * from example2

Once we run above script our table’s example1 and example2 will create and result will be like as shown following image

 

Create new table in sql server database

 

Now our tables are ready write queries like as shown below in examples to check ANY Operator

SQL Any Operator Example

Now run following sql query to check how to use sql any operator

 

SELECT id,name FROM example1

WHERE id = ANY(SELECT Id FROM example2)

When we run above sql query we will get sql any operator result like as shown below

 

SQL Any Operator Example Result or Output

 

Because in above query “id” in example1 table will compare with all ids in example2 table like as shown below 

 

   (example1:id1 = example2:id1)

   OR (example1:id1 = example2:id4)

   OR (example1:id1 = example2:id5)

SQL Any Operator Example 2

We will check any operator with another example. Write sql query like as shown below to use sql any operator

 

SELECT id,name FROM example1

id >= ANY(SELECT Id FROM example2)

When we run above query it will return result like as shown below 

 

SQL Server ANy Operator Example Result or Output

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User