×

SQL Operators

Arithmetic Operators

Arithmetic operators are +, -, *, /, % performs addition, subtraction, multiplication, division, modulo respectively. Example:  
  • Select 100+222;
  • Select salary+100
From teacher Where teacher_id=1; Following output screen shows different arithmetic operations. We can perform single operation at a time or multiple operations.

Comparison Operators

Comparison operators ‘<’,   ‘<=’, ‘>’, >, =’, =’ performs less than, less than equal, greater than, greater than equal, equal respectively. Following output screen shows different comparison operators. Following output screen shows different queries with different comparison operations.  

Logical Operators

AND, OR, NOT, LIKE, IN, BETWEEN, ALL, SOME, ANY, EXISTS are logical operators from which some operators ALL, ANY, EXISTS, SOME used in sub queries. AND: It returns TRUE, if all the conditions separated by AND are TRUE. Example: Select * from teacher where salary>10000 and dept_name=’CS’; OR: It returns TRUE, if any of the conditions separated by OR is TRUE. Example: Select * from teacher where salary < 10000 OR dept_name=’IT’;   BETWEEN: It returns true, if the operands are within the range of comparison. Example: Select * from teacher where teacher_id between 4 and 8;   IN: It returns true if the operand is equal to one of the list of expressions. Example: Select * from teacher where teacher_id in (4,8); LIKE: It returns true if the operand matches a pattern. ‘_’ underscore represents single character. ‘%’ percent represents one or more characters. Example: Q1. Find out teachers whose name start with ‘a’? Select teacher_name from teacher where teacher_name like 'a%'; Q2 Find out teachers whose name end with ‘r’? Select teacher_name from teacher where teacher_name like '%r'; Q3 Find out teachers whose name contains letter ‘h’? Select teacher_name from teacher where teacher_name like '%h%'; Q4 Find out teacher whose name contains ‘h’ letter at third position? Select teacher_name from teacher where teacher_name like '__h%';   If the condition is not true. Example: Select teacher_name from teacher where teacher_name NOT like '%h%';   Reference: https://www.javatpoint.com/sql-operators

Related Topics

SQL SELECT BETWEEN Operator

This SQL tutorial explains and helps us understand how to use the BETWEEN operator in the SELECT query with examples. The SQL SELECT BETWEEN operator retrieves the data from the table...

2 minutes read.

How to use HAVING clause in SQL

In this article, we will learn about the HAVING clause concept and how to use it in SQL. What is the HAVING clause? In Structured Query Language, HAVING Clause used with GROUP...

7 minutes read.

SQL Top Clause

Top Clause: It returns the first ‘n’ number of rows as output. This Top clause is used to retrieve the required number of rows when there are thousands of records stored...

3 minutes read.

How to use the BETWEEN operator in SQL

In this entire SQL article, we will understand and learn about the BETWEEN operator concept and how to use it in SQL. What is the BETWEEN operator in SQL? The Between operator...

4 minutes read.

Codd’s Rules in SQL

Codd’s Rules Dr. Edgar F. Codd, in 1985, laid down 13 fundamental rules after doing large-scale research on the Relational Model of databases. According to him, every database must follow these...

3 minutes read.

SQL Comparision Operator

The Comparison Operator compares different data of the Structured Query Language table and checks whether the data are the same, less than, greater than, less than, or greater than equal....

14 minutes read.

SQL Data Control Language

Data Control Language decides to whom should (which user) permit access privileges. GRANT and REVOKE are the commands of DCL. GRANT: It gives privileges to user. REVOKE: It takes back privileges from granted...

1 minute read.

SQL Inner Join

In Structured Query Language, the most used join query is the Inner join query. Inner join query retrieves the records from one or more tables with similar data or records. The...

4 minutes read.

How to add column in table in SQL ?

How to add column in table in SQL  Introduction To add a column in already created table, one needs to use the ALTER command along with the ADD clause.If in the query,...

7 minutes read.

SQL Tutorial for Beginners

SQL tutorial provides basic and advanced concepts of Structured Query Language and how you deploy SQL to work with a relational database system. Our SQL tutorial is designed for beginners...

3 minutes read.

SQL INSERT INTO SELECT

In this tutorial, we will help you to understand and learn how to copy records from one table and add them to another table in the SQL with the help...

5 minutes read.

SQL Data Types

In SQL DATA TYPES, each column holds value. Data types can be an integer type, character type, etc., and such data is stored in the database table. The data type is...

4 minutes read.

GROUP BY vs ORDER BY

The GROUP BY clause and ORDER BY clause in SQL are used to arrange data obtained by SQL queries. The important difference between the GROUP BY clause and ORDER BY...

4 minutes read.

Check Constraint in SQL

The Check Constraint in SQL is the rule or set of rules used to limit the data range that can be entered in a table column. Check constraint is used...

8 minutes read.

SQL DROP Database

This tutorial will help us understand how to drop a database from the SQL Server with a few examples. The DROP command removes all the objects stored in the database and...

4 minutes read.

Trigger in SQL

In this article, we will learn about the concept of trigger in SQL and its implementation with the help of an example. A Trigger in Structured Query Language is a set...

4 minutes read.

SQL ORDER BY

SQL ORDER BY The SQL ORDER BY clause is used to sort the data stored in tables in the database. The sorting can be done in an ascending way, descending way,...

5 minutes read.

SQL Count

Structured Query Language Count() Function is used with Structured Query Language SELECT Statement. SQL Count() function returns the number of items that match the specified criteria in the SELECT statement. Count()...

2 minutes read.

SQL SELECT SUM

The SQL Sum() function is an aggregate function in SQL that returns the total values of an expression. The expression may be numerical, or it may be an expression. Syntax: SELECT SUM(columnname)...

3 minutes read.

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.