By 25/02/2016 1 Comments

What Are MID() & SUBSTRING() Functions In SQL?

  • SQL MID() and SUBSTRING() functions extract or return the string characters of values from a table column.
  • These functions return string values based on given parameters, these parameters are column name, starting character’s position and length of characters to be return of a particular string in table column.
  • The MID() function is used in MySQL database system.
  • The SUBSTRING() function us used in SQL Server database system.

Syntax for MySQL:

SELECT MID(column,startPos,length) AS some_name FROM table_name;

Example:

SELECT id, MID(product_name, 1, 3) AS "Products contains 3 characters", price
FROM products;
  • In above query example the MID() function returns all products with 3 characters in table (products).

Syntax for SQL Server:

SELECT SUBSTRING(column,startPos,length) AS some_name FROM table_name;

Example:

SELECT id, SUBSTRING(product_name, 1, 3) AS "Products contains 3 characters", price
FROM products;
  • In above query example the SUBSTRING() function returns all products with 3 characters in table (products).






Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .