Friday 16 January 2015

What are the Operators used in SQL ?

  

  1. Comparison Operator :  < , > , < > , = , ! = , <= , >= , !< , !> 
          Comparison operators are used to compare the column data with specific values in a      condition. Comparison Operators are also used along with the SELECT statement to filter      data based on specific conditions.
  
         Example : Select Column_name(s) from table_name where 
                         column_name != some_value

    2. Range Operator : Between , Not Between

         A range search is one that returns all values between two specified values. Inclusive ranges return any values that match the two specified values. Exclusive ranges do not return any values that match the two specified values. 

        Example : Select Column_name(s) from table_name where 
                         column_name Between value1 AND value2
         
    3. List Operator : In , Not IN

         The IN keyword allows you to select rows that match any one of a list of values. For example, without IN, if you want a list of the products in the Frames subcategory, you would need this query. 

        Example : Select Column_name(s) from table_name where 
                         column_name IN (value1 ,value2)
  
   4. String Operator : Like , Not Like

         The LIKE keyword searches for character string, date, or time values that match a specified pattern. The LIKE keyword uses a regular expression to contain the pattern that the values are matched against. The pattern contains the character string to search for, which can contain any combination of four wildcards.

        Example : Select Column_name(s) from table_name where 
                         column_name Like a%. 

      
Wildcard
Meaning
%
Any string of zero or more characters.
_
Any single character.
[ ]
Any single character within the specified range (for example, [a-f]) or set (for example, [abcdef]).
[^]
Any single character not within the specified range (for example, [^a - f]) or set (for example, [^abcdef]).

          

   5. Logical Operators : And , OR , NOT

          The logical operators are AND, OR, and NOT. AND and OR are used to connect search conditions in WHERE clauses. NOT reverses the result of a search condition.

        Example 1 : Select Column_name(s) from table_name where 
                         column_name1 = SOMEVALUE and column_name2 =somevalue 
  
        In this Example only if both the conditions are true , it will return the result.

          Example 2 : Select Column_name(s) from table_name where 
                          column_name1 = SOMEVALUE or column_name2 =somevalue 

        In this Example , if any one of the conditions are true , it will return the result.

        Example 3 : Select Column_name(s) from table_name where 
                         (column_name1 = SOMEVALUE or column_name2 =somevalue)
                          and column_name3 = SOMEVALUE   
         
                

No comments:

Post a Comment