SUMMARY
In this article we will learn about in operator and not in operator in sql. Generally to filter data from any table we use where clause along with condition.When we are using more than one value to filter data from the database table then in operator plays role to solve this issue and the query has become simple.
PREREQUISITE
First we need to login our mysql server using the below command.
$mysql - u root -p
Now you need to create mysql database and table .Then check all database list and select our prefered database. To show database list we will use the below command.
mysql>show databases;
you select your database as per your requirement. In our case we select techrideradmin database . Then select the table list within the database. In our case we select dept table. Now fetch all records form the table.
WHAT IS IN OPERATOR
In case of in operator we will get those rows which we have provided within the in values along with where statement.
EXAMPLE OF IN OPERATOR
we will fetch those records which department nos belong to 1,3 and 5 using in operator.
mysql > select * from dept where deptno in (1,3,5);
WHAT IS NOT IN OPERATOR
In case of not in operator we will get those rows which is not provided within the not in operator.
EXAMPLE OF NOT IN OPERATOR
We will also fetch the records which dept nos are not belong to 1,3 and 5 using not in operator.
mysql > select * from dept where deptno not in (1,3,5);
Note: you can find the above video tutorial for reference.
CONCLUSION
we have learned about in operator in sql and not in operator in sql .
0 comments:
Post a Comment