SQL Operators

SQL Operators

SQL Operators

SQL operators are symbols or keywords used in SQL statements to perform specific operations on data. There are several types of operators in SQL, including:

  1. Arithmetic Operators: Arithmetic operators are used to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus. Here are the basic arithmetic operators in SQL:
  • (addition)
  • (subtraction)
  • (multiplication)
  • / (division)
  • % (modulus)

Example: SELECT (10 + 5) * 3 AS Result; — Output: 45

  1. Comparison Operators: Comparison operators are used to compare values and return a boolean result (true or false). Here are the comparison operators in SQL:
  • = (equal to)
  • <> or != (not equal to)
  • (greater than)
  • < (less than)
  • = (greater than or equal to)
  • <= (less than or equal to)

Example: SELECT * FROM Customers WHERE City = ‘New York’;

  1. Logical Operators: Logical operators are used to combine multiple conditions and return a boolean result (true or false). Here are the logical operators in SQL:
  • AND (returns true if both conditions are true)
  • OR (returns true if either condition is true)
  • NOT (returns true if the condition is false)

Example: SELECT * FROM Customers WHERE City = ‘New York’ AND Country = ‘USA’;

  1. Bitwise Operators: Bitwise operators are used to perform operations on binary numbers. Here are the bitwise operators in SQL:
  • & (bitwise AND)
  • | (bitwise OR)
  • ^ (bitwise XOR)
  • ~ (bitwise NOT)
  • << (bitwise left shift)
  • (bitwise right shift)

Example: SELECT 2 | 1; — Output: 3

These are some of the common operators in SQL. Understanding how to use them can help you write more complex SQL queries and manipulate data in a more efficient way.

Join To Get Our Newsletter
Spread the love