bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL

SQL

SQL References

SQL References focused on SQL Data Types for MySQL, SQL Server, and MS Access and related concepts.

Lesson 1visual

SQL Data Types for MySQL, SQL Server, and MS Access

SQL Data Types for MySQL, SQL Server, and MS Access

10 min
Read lesson →
Lesson 2visual

SQL Keywords Reference

This SQL keywords reference contains the reserved words in SQL. SQL Keywords Keyword Description ADD Adds a column in an existing table ADD CONSTRAINT Adds a constraint after a table is already creat…

5 min
Read lesson →
Lesson 3visual

SQL ADD Keyword

ADD Keyword ❮ SQL Keywords Next ADD The ADD command is used to add a column in an existing table. Example Add an "Email" column to the "Customers" table: ALTER TABLE Customers ADD Email varchar(255);…

2 min
Read lesson →
Lesson 4visual

SQL ADD CONSTRAINT Keyword

ADD CONSTRAINT Keyword Previous ❮ SQL Keywords Next ADD CONSTRAINT The ADD CONSTRAINT command is used to create a constraint after a table is already created. The following SQL adds a constraint name…

2 min
Read lesson →
Lesson 5visual

SQL ALL Keyword

ALL Keyword Previous ❮ SQL Keywords Next ALL The ALL command returns true if all of the subquery values meet the condition. The following SQL statement returns TRUE and lists the productnames if ALL…

2 min
Read lesson →
Lesson 6visual

SQL ALTER Keyword

ALTER Keyword Previous ❮ SQL Keywords Next ALTER TABLE The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints in a ta…

2 min
Read lesson →
Lesson 7visual

SQL ALTER COLUMN Keyword

ALTER COLUMN Keyword Previous ❮ SQL Keywords Next ALTER COLUMN The ALTER COLUMN command is used to change the data type of a column in a table. The following SQL changes the data type of the column n…

2 min
Read lesson →
Lesson 8visual

SQL ALTER TABLE Keyword

ALTER TABLE Keyword Previous ❮ SQL Keywords Next ALTER TABLE The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints i…

2 min
Read lesson →
Lesson 9visual

SQL ALTER VIEW Keyword

ALTER VIEW Keyword Previous ❮ SQL Keywords Next ALTER VIEW In SQL Server, a view can be updated with the ALTER VIEW command. The following SQL adds the "City" column to the "Brazil Customers" view: E…

2 min
Read lesson →
Lesson 10visual

SQL AND Keyword

AND Keyword Previous ❮ SQL Keywords Next AND The AND command is used with WHERE to only include rows where both conditions is true. The following SQL statement selects all fields from "Customers" whe…

2 min
Read lesson →
Lesson 11visual

SQL ANY Keyword

ANY Keyword Previous ❮ SQL Keywords Next ANY The ANY command returns true if any of the subquery values meet the condition. The following SQL statement returns TRUE and lists the productnames if it f…

2 min
Read lesson →
Lesson 12visual

SQL AS Keyword

AS Keyword Previous ❮ SQL Keywords Next AS The AS command is used to rename a column or table with an alias. An alias only exists for the duration of the query. Alias for Columns The following SQL st…

2 min
Read lesson →
Lesson 13visual

SQL ASC Keyword

ASC Keyword Previous ❮ SQL Keywords Next ASC The ASC command is used to sort the data returned in ascending order. The following SQL statement selects all the columns from the "Customers" table, sort…

2 min
Read lesson →
Lesson 14visual

SQL BACKUP DATABASE Keyword

SQL BACKUP DATABASE Keyword

2 min
Read lesson →
Lesson 15visual

SQL BETWEEN Keyword

BETWEEN Keyword Previous ❮ SQL Keywords Next BETWEEN The BETWEEN command is used to select values within a given range. The values can be numbers, text, or dates. The BETWEEN command is inclusive: be…

2 min
Read lesson →
Lesson 16visual

SQL CASE Keyword

CASE Keyword Previous ❮ SQL Keywords Next CASE The CASE command is used is to create different output based on conditions. The following SQL goes through several conditions and returns a value when t…

2 min
Read lesson →
Lesson 17visual

SQL CHECK Keyword

CHECK Keyword Previous ❮ SQL Keywords Next CHECK The CHECK constraint limits the value that can be placed in a column. SQL CHECK on CREATE TABLE The following SQL creates a CHECK constraint on the "A…

2 min
Read lesson →
Lesson 18visual

SQL COLUMN Keyword

COLUMN Keyword Previous ❮ SQL Keywords Next ALTER COLUMN The ALTER COLUMN command is used to change the data type of a column in a table. The following SQL changes the data type of the column named "…

2 min
Read lesson →
Lesson 19visual

SQL CONSTRAINT Keyword

CONSTRAINT Keyword Previous ❮ SQL Keywords Next ADD CONSTRAINT The ADD CONSTRAINT command is used to create a constraint after a table is already created. The following SQL adds a constraint named "P…

2 min
Read lesson →
Lesson 20visual

SQL CREATE Keyword

SQL CREATE Keyword

3 min
Read lesson →
Lesson 21visual

SQL CREATE DATABASE Keyword

SQL CREATE DATABASE Keyword

2 min
Read lesson →
Lesson 22visual

SQL CREATE INDEX Keyword

CREATE INDEX Keyword Previous ❮ SQL Keywords Next CREATE INDEX The CREATE INDEX command is used to create indexes in tables (allows duplicate values). Indexes are used to retrieve data from the datab…

2 min
Read lesson →
Lesson 23visual

SQL CREATE OR REPLACE VIEW Keyword

CREATE OR REPLACE VIEW Keyword Previous ❮ SQL Keywords Next CREATE OR REPLACE VIEW In MySQL and Oracle, a view can be updated with the CREATE OR REPLACE VIEW command. The following SQL adds the "City…

2 min
Read lesson →
Lesson 24visual

SQL CREATE TABLE Keyword

CREATE TABLE Keyword Previous ❮ SQL Keywords Next CREATE TABLE The CREATE TABLE command creates a new table in the database. The following SQL creates a table called "Persons" that contains five colu…

2 min
Read lesson →
Lesson 25visual

SQL CREATE PROCEDURE Keyword

CREATE PROCEDURE Keyword Previous ❮ SQL Keywords Next CREATE PROCEDURE The CREATE PROCEDURE command is used to create a stored procedure. A stored procedure is a prepared SQL code that you can save,…

2 min
Read lesson →
Lesson 26visual

SQL CREATE UNIQUE INDEX Keyword

CREATE UNIQUE INDEX Keyword Previous ❮ SQL Keywords Next CREATE UNIQUE INDEX The CREATE UNIQUE INDEX command creates a unique index on a table (no duplicate values allowed) Indexes are used to retrie…

2 min
Read lesson →
Lesson 27visual

SQL CREATE VIEW Keyword

CREATE VIEW Keyword Previous ❮ SQL Keywords Next CREATE VIEW The CREATE VIEW command creates a view. A view is a virtual table based on the result set of an SQL statement. The following SQL creates a…

2 min
Read lesson →
Lesson 28visual

SQL DATABASE Keyword

SQL DATABASE Keyword

2 min
Read lesson →
Lesson 29visual

SQL DEFAULT Keyword

DEFAULT Keyword Previous ❮ SQL Keywords Next DEFAULT The DEFAULT constraint provides a default value for a column. The default value will be added to all new records if no other value is specified. S…

2 min
Read lesson →
Lesson 30visual

SQL DELETE Keyword

DELETE Keyword Previous ❮ SQL Keywords Next DELETE The DELETE command is used to delete existing records in a table. The following SQL statement deletes the customer "Alfreds Futterkiste" from the "C…

2 min
Read lesson →
Lesson 31visual

SQL DESC Keyword

DESC Keyword Previous ❮ SQL Keywords Next DESC The DESC command is used to sort the data returned in descending order. The following SQL statement selects all the columns from the "Customers" table,…

2 min
Read lesson →
Lesson 32visual

SQL SELECT DISTINCT Keyword

SELECT DISTINCT Keyword Previous ❮ SQL Keywords Next SELECT DISTINCT The SELECT DISTINCT command returns only distinct (different) values in the result set. The following SQL statement selects only t…

2 min
Read lesson →
Lesson 33visual

SQL DROP Keyword

DROP Keyword Previous ❮ SQL Keywords Next DROP COLUMN The DROP COLUMN command is used to delete a column in an existing table. The following SQL deletes the "ContactName" column from the "Customers"…

2 min
Read lesson →
Lesson 34visual

SQL DROP COLUMN Keyword

DROP COLUMN Keyword Previous ❮ SQL Keywords Next DROP COLUMN The DROP COLUMN command is used to delete a column in an existing table. The following SQL deletes the "ContactName" column from the "Cust…

2 min
Read lesson →
Lesson 35visual

SQL DROP CONSTRAINT Keyword

DROP CONSTRAINT Keyword Previous ❮ SQL Keywords Next DROP CONSTRAINT The DROP CONSTRAINT command is used to delete a UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK constraint. DROP a UNIQUE Constraint To…

2 min
Read lesson →
Lesson 36visual

SQL DROP DATABASE Keyword

DROP DATABASE Keyword Previous ❮ SQL Keywords Next DROP DATABASE The DROP DATABASE command is used to delete an existing SQL database. The following SQL drops a database named "testDB": Example DROP…

2 min
Read lesson →
Lesson 37visual

SQL DROP DEFAULT Keyword

DROP DEFAULT Keyword Previous ❮ SQL Keywords Next DROP DEFAULT The DROP DEFAULT command is used to delete a DEFAULT constraint. To drop a DEFAULT constraint, use the following SQL: SQL Server / Oracl…

2 min
Read lesson →
Lesson 38visual

SQL DROP INDEX Keyword

DROP INDEX Keyword Previous ❮ SQL Keywords Next DROP INDEX The DROP INDEX command is used to delete an index in a table. MS Access: DROP INDEX index_name ON table_name ; SQL Server: DROP INDEX table_…

2 min
Read lesson →
Lesson 39visual

SQL DROP TABLE and TRUNCATE TABLE Keywords

DROP TABLE and TRUNCATE TABLE Keywords Previous ❮ SQL Keywords Next DROP TABLE The DROP TABLE command deletes a table in the database. The following SQL deletes the table "Shippers": Example DROP TAB…

2 min
Read lesson →
Lesson 40visual

SQL DROP VIEW Keyword

DROP VIEW Keyword Previous ❮ SQL Keywords Next DROP VIEW The DROP VIEW command deletes a view. The following SQL drops the "Brazil Customers" view: Example DROP VIEW [Brazil Customers]; Previous ❮ SQ…

2 min
Read lesson →
Lesson 41visual

SQL EXEC Keyword

EXEC Keyword Previous ❮ SQL Keywords Next EXEC The EXEC command is used to execute a stored procedure. The following SQL executes a stored procedure named "SelectAllCustomers": Example EXEC SelectAll…

2 min
Read lesson →
Lesson 42visual

SQL EXISTS Keyword

EXISTS Keyword Previous ❮ SQL Keywords Next EXISTS The EXISTS command tests for the existence of any record in a subquery, and returns true if the subquery returns one or more records. The following…

2 min
Read lesson →
Lesson 43visual

SQL FOREIGN KEY Keyword

FOREIGN KEY Keyword Previous ❮ SQL Keywords Next FOREIGN KEY The FOREIGN KEY constraint is a key used to link two tables together. A FOREIGN KEY is a field (or collection of fields) in one table that…

2 min
Read lesson →
Lesson 44visual

SQL FROM Keyword

FROM Keyword Previous ❮ SQL Keywords Next FROM The FROM command is used to specify which table to select or delete data from. The following SQL statement selects the "CustomerName" and "City" columns…

2 min
Read lesson →
Lesson 45visual

SQL FULL OUTER JOIN Keyword

FULL OUTER JOIN Keyword Previous ❮ SQL Keywords Next FULL OUTER JOIN The FULL OUTER JOIN command returns all rows when there is a match in either left table or right table. The following SQL statemen…

2 min
Read lesson →
Lesson 46visual

SQL GROUP BY Keyword

GROUP BY Keyword Previous ❮ SQL Keywords Next GROUP BY The GROUP BY command is used to group the result set (used with aggregate functions: COUNT, MAX, MIN, SUM, AVG). The following SQL lists the num…

2 min
Read lesson →
Lesson 47visual

SQL HAVING Keyword

HAVING Keyword Previous ❮ SQL Keywords Next HAVING The HAVING command is used instead of WHERE with aggregate functions. The following SQL lists the number of customers in each country. Only include…

2 min
Read lesson →
Lesson 48visual

SQL IN Keyword

IN Keyword Previous ❮ SQL Keywords Next IN The IN operator is used in the WHERE clause to check if a specified column's value matches any value within a provided list. The IN operator functions as a…

2 min
Read lesson →
Lesson 49visual

SQL INDEX Keyword

INDEX Keyword Previous ❮ SQL Keywords Next CREATE INDEX The CREATE INDEX command is used to create indexes in tables (allows duplicate values). Indexes are used to retrieve data from the database ver…

2 min
Read lesson →
Lesson 50visual

SQL INNER JOIN Keyword

INNER JOIN Keyword Previous ❮ SQL Keywords Next INNER JOIN The INNER JOIN command returns rows that have matching values in both tables. The following SQL selects all orders with customer information…

2 min
Read lesson →
Lesson 51visual

SQL INSERT INTO Keyword

INSERT INTO Keyword Previous ❮ SQL Keywords Next INSERT INTO The INSERT INTO command is used to insert new rows in a table. The following SQL inserts a new record in the "Customers" table: Example IN…

2 min
Read lesson →
Lesson 52visual

SQL INSERT INTO SELECT Keyword

INSERT INTO SELECT Keyword Previous ❮ SQL Keywords Next INSERT INTO SELECT The INSERT INTO SELECT command copies data from one table and inserts it into another table. The following SQL copies "Suppl…

2 min
Read lesson →
Lesson 53visual

SQL IS NULL Keyword

SQL IS NULL Keyword

2 min
Read lesson →
Lesson 54visual

SQL IS NOT NULL Keyword

IS NOT NULL Keyword Previous ❮ SQL Keywords Next IS NOT NULL The IS NOT NULL command is used to test for non-empty values (NOT NULL values). The following SQL lists all customers with a value in the…

2 min
Read lesson →
Lesson 55visual

SQL JOIN Keyword

JOIN Keyword Previous ❮ SQL Keywords Next INNER JOIN The INNER JOIN command returns rows that have matching values in both tables. The following SQL selects all orders with customer information: Exam…

2 min
Read lesson →
Lesson 56visual

SQL LEFT JOIN Keyword

LEFT JOIN Keyword Previous ❮ SQL Keywords Next LEFT JOIN The LEFT JOIN command returns all rows from the left table, and the matching rows from the right table. The result is NULL from the right side…

2 min
Read lesson →
Lesson 57visual

SQL LIKE Keyword

LIKE Keyword Previous ❮ SQL Keywords Next LIKE The LIKE command is used in a WHERE clause to search for a specified pattern in a column. You can use two wildcards with LIKE % - Represents zero, one,…

2 min
Read lesson →
Lesson 58visual

SQL SELECT TOP, LIMIT and ROWNUM Keywords

SELECT TOP, LIMIT and ROWNUM Keywords Previous ❮ SQL Keywords Next SELECT TOP, LIMIT and ROWNUM The LIMIT, SELECT TOP or ROWNUM command is used to specify the number of records to return. Note: SQL S…

2 min
Read lesson →
Lesson 59visual

SQL NOT Keyword

NOT Keyword Previous ❮ SQL Keywords Next NOT The NOT command is used with WHERE to only include rows where a condition is not true. The following SQL statement selects all fields from "Customers" whe…

2 min
Read lesson →
Lesson 60visual

SQL NOT NULL Keyword

NOT NULL Keyword Previous ❮ SQL Keywords Next NOT NULL The NOT NULL constraint enforces a column to not accept NULL values, which means that you cannot insert or update a record without adding a valu…

2 min
Read lesson →
Lesson 61visual

SQL OR Keyword

OR Keyword Previous ❮ SQL Keywords Next OR The OR command is used with WHERE to include rows where either condition is true. The following SQL statement selects all fields from "Customers" where city…

2 min
Read lesson →
Lesson 62visual

SQL ORDER BY Keyword

ORDER BY Keyword Previous ❮ SQL Keywords Next ORDER BY The ORDER BY command is used to sort the result set in ascending or descending order. The ORDER BY command sorts the result set in ascending ord…

2 min
Read lesson →
Lesson 63visual

SQL FULL OUTER JOIN Keyword

FULL OUTER JOIN Keyword Previous ❮ SQL Keywords Next FULL OUTER JOIN The FULL OUTER JOIN command returns all rows when there is a match in either left table or right table. The following SQL statemen…

2 min
Read lesson →
Lesson 64visual

SQL PRIMARY KEY Keyword

PRIMARY KEY Keyword Previous ❮ SQL Keywords Next PRIMARY KEY The PRIMARY KEY constraint uniquely identifies each record in a table. A table can have only one primary key, which may consist of one sin…

2 min
Read lesson →
Lesson 65visual

SQL CREATE PROCEDURE Keyword

CREATE PROCEDURE Keyword Previous ❮ SQL Keywords Next CREATE PROCEDURE The CREATE PROCEDURE command is used to create a stored procedure. A stored procedure is a prepared SQL code that you can save,…

2 min
Read lesson →
Lesson 66visual

SQL RIGHT JOIN Keyword

RIGHT JOIN Keyword Previous ❮ SQL Keywords Next RIGHT JOIN The RIGHT JOIN command returns all rows from the right table, and the matching records from the left table. The result is NULL from the left…

2 min
Read lesson →
Lesson 67visual

SQL SELECT TOP, LIMIT and ROWNUM Keywords

SELECT TOP, LIMIT and ROWNUM Keywords Previous ❮ SQL Keywords Next SELECT TOP, LIMIT and ROWNUM The LIMIT, SELECT TOP or ROWNUM command is used to specify the number of records to return. Note: SQL S…

2 min
Read lesson →
Lesson 68visual

SQL SELECT Keyword

SELECT Keyword Previous ❮ SQL Keywords Next SELECT The SELECT command is used to select data from a database. The data returned is stored in a result table, called the result set. The following SQL s…

2 min
Read lesson →
Lesson 69visual

SQL SELECT DISTINCT Keyword

SELECT DISTINCT Keyword Previous ❮ SQL Keywords Next SELECT DISTINCT The SELECT DISTINCT command returns only distinct (different) values in the result set. The following SQL statement selects only t…

2 min
Read lesson →
Lesson 70visual

SQL SELECT INTO Keyword

SELECT INTO Keyword Previous ❮ SQL Keywords Next SELECT INTO The SELECT INTO command copies data from one table and inserts it into a new table. The following SQL statement creates a backup copy of C…

2 min
Read lesson →
Lesson 71visual

SQL SELECT TOP, LIMIT and ROWNUM Keywords

SELECT TOP, LIMIT and ROWNUM Keywords Previous ❮ SQL Keywords Next SELECT TOP, LIMIT and ROWNUM The LIMIT, SELECT TOP or ROWNUM command is used to specify the number of records to return. Note: SQL S…

2 min
Read lesson →
Lesson 72visual

SQL SET Keyword

SET Keyword Previous ❮ SQL Keywords Next SET The SET command is used with UPDATE to specify which columns and values that should be updated in a table. The following SQL updates the first customer (C…

2 min
Read lesson →
Lesson 73visual

SQL TABLE Keyword

TABLE Keyword Previous ❮ SQL Keywords Next CREATE TABLE The CREATE TABLE command creates a new table in the database. The following SQL creates a table called "Persons" that contains five columns: Pe…

2 min
Read lesson →
Lesson 74visual

SQL SELECT TOP, LIMIT and ROWNUM Keywords

SELECT TOP, LIMIT and ROWNUM Keywords Previous ❮ SQL Keywords Next SELECT TOP, LIMIT and ROWNUM The LIMIT, SELECT TOP or ROWNUM command is used to specify the number of records to return. Note: SQL S…

2 min
Read lesson →
Lesson 75visual

SQL DROP TABLE and TRUNCATE TABLE Keywords

DROP TABLE and TRUNCATE TABLE Keywords Previous ❮ SQL Keywords Next DROP TABLE The DROP TABLE command deletes a table in the database. The following SQL deletes the table "Shippers": Example DROP TAB…

2 min
Read lesson →
Lesson 76visual

SQL UNION Keyword

UNION Keyword Previous ❮ SQL Keywords Next UNION The UNION command combines the result set of two or more SELECT statements (only distinct values) The following SQL statement returns the cities (only…

2 min
Read lesson →
Lesson 77visual

SQL UNION ALL Keyword

UNION ALL Keyword Previous ❮ SQL Keywords Next UNION ALL The UNION ALL command combines the result set of two or more SELECT statements (allows duplicate values). The following SQL statement returns…

2 min
Read lesson →
Lesson 78visual

SQL UNIQUE Keyword

UNIQUE Keyword Previous ❮ SQL Keywords Next UNIQUE The UNIQUE constraint ensures that all values in a column are unique. SQL UNIQUE Constraint on CREATE TABLE The following SQL creates a UNIQUE const…

2 min
Read lesson →
Lesson 79visual

SQL UPDATE Keyword

UPDATE Keyword Previous ❮ SQL Keywords Next UPDATE The UPDATE command is used to update existing rows in a table. The following SQL statement updates the first customer (CustomerID = 1) with a new co…

2 min
Read lesson →
Lesson 80visual

SQL VALUES Keyword

VALUES Keyword Previous ❮ SQL Keywords Next VALUES The VALUES command specifies the values of an INSERT INTO statement. The following SQL inserts a new record in the "Customers" table: Example INSERT…

2 min
Read lesson →
Lesson 81visual

SQL VIEW Keyword

VIEW Keyword Previous ❮ SQL Keywords Next CREATE VIEW In SQL, a view is a virtual table based on the result set of an SQL statement. The CREATE VIEW command creates a view. The following SQL creates…

2 min
Read lesson →
Lesson 82visual

SQL WHERE Keyword

WHERE Keyword Previous ❮ SQL Keywords Next SELECT The WHERE command filters a result set to include only records that fulfill a specified condition. The following SQL statement selects all the custom…

2 min
Read lesson →
Lesson 83visual

MySQL Functions

MySQL has many built-in functions. This reference contains string, numeric, date, and some advanced functions in MySQL. MySQL String Functions Function Description ASCII Returns the ASCII value for t…

8 min
Read lesson →
Lesson 84visual

MySQL ASCII() Function

Example Return the ASCII value of the first character in "CustomerName": SELECT ASCII(CustomerName) AS NumCodeOfFirstChar FROM Customers; Definition and Usage The ASCII() function returns the ASCII v…

2 min
Read lesson →
Lesson 85visual

MySQL CHAR_LENGTH() Function

Example Return the length of the string: SELECT CHAR_LENGTH("SQL Tutorial") AS LengthOfString; Definition and Usage The CHAR_LENGTH() function return the length of a string (in characters). Note: Thi…

2 min
Read lesson →
Lesson 86visual

MySQL CHARACTER_LENGTH() Function

Example Return the length of the string: SELECT CHARACTER_LENGTH("SQL Tutorial") AS LengthOfString; Definition and Usage The CHARACTER_LENGTH() function return the length of a string (in characters).…

2 min
Read lesson →
Lesson 87visual

MySQL CONCAT() Function

Example Add several strings together: SELECT CONCAT("SQL ", "Tutorial ", "is ", "fun!") AS ConcatenatedString; Definition and Usage The CONCAT() function adds two or more expressions together. Note:…

2 min
Read lesson →
Lesson 88visual

MySQL CONCAT_WS() Function

Example Add several expressions together, and add a "-" separator between them: SELECT CONCAT_WS("-", "SQL", "Tutorial", "is", "fun!") AS ConcatenatedString; Definition and Usage The CONCAT_WS() func…

2 min
Read lesson →
Lesson 89visual

MySQL FIELD() Function

Example Return the index position of "q" in the string list: SELECT FIELD("q", "s", "q", "l"); Definition and Usage The FIELD() function returns the index position of a value in a list of values. Thi…

2 min
Read lesson →
Lesson 90visual

MySQL FIND_IN_SET() Function

Example Search for "q" within the list of strings: SELECT FIND_IN_SET("q", "s,q,l"); Definition and Usage The FIND_IN_SET() function returns the position of a string within a list of strings. Syntax…

2 min
Read lesson →
Lesson 91visual

MySQL FORMAT() Function

Example Format the number as "#,###,###.##" (and round with two decimal places): SELECT FORMAT(250500.5634, 2); Definition and Usage The FORMAT() function formats a number to a format like "#,###,###…

2 min
Read lesson →
Lesson 92visual

MySQL INSERT() Function

Example Insert the string "Example" into the string "W3Schools.com". Replace the first nine characters: SELECT INSERT("W3Schools.com", 1, 9, "Example"); Definition and Usage The INSERT() function ins…

2 min
Read lesson →
Lesson 93visual

MySQL INSTR() Function

Example Search for "3" in string "W3Schools.com", and return position: SELECT INSTR("W3Schools.com", "3") AS MatchPosition; Definition and Usage The INSTR() function returns the position of the first…

2 min
Read lesson →
Lesson 94visual

MySQL LCASE() Function

Example Convert the text to lower-case: SELECT LCASE("SQL Tutorial is FUN!"); Definition and Usage The LCASE() function converts a string to lower-case. Note: The LOWER() function is a synonym for th…

2 min
Read lesson →
Lesson 95visual

MySQL LEFT() Function

MySQL LEFT() Function

2 min
Read lesson →
Lesson 96visual

MySQL LENGTH() Function

Example Return the length of the string, in bytes: SELECT LENGTH("SQL Tutorial") AS LengthOfString; Definition and Usage The LENGTH() function returns the length of a string (in bytes). Syntax LENGTH…

2 min
Read lesson →
Lesson 97visual

MySQL LOCATE() Function

Example Search for "3" in string "W3Schools.com", and return position: SELECT LOCATE("3", "W3Schools.com") AS MatchPosition; Definition and Usage The LOCATE() function returns the position of the fir…

2 min
Read lesson →
Lesson 98visual

MySQL LOWER() Function

Example Convert the text to lower-case: SELECT LOWER("SQL Tutorial is FUN!"); Definition and Usage The LOWER() function converts a string to lower-case. Note: The LCASE() function is equal to the LOW…

2 min
Read lesson →
Lesson 99visual

MySQL LPAD() Function

Example Left-pad the string with "ABC", to a total length of 20: SELECT LPAD("SQL Tutorial", 20, "ABC"); Definition and Usage The LPAD() function left-pads a string with another string, to a certain…

2 min
Read lesson →
Lesson 100visual

MySQL LTRIM() Function

Example Remove leading spaces from a string: SELECT LTRIM(" SQL Tutorial") AS LeftTrimmedString; Definition and Usage The LTRIM() function removes leading spaces from a string. Syntax LTRIM( string )…

2 min
Read lesson →
Lesson 101visual

MySQL MID() Function

Example Extract a substring from a string (start at position 5, extract 3 characters): SELECT MID("SQL Tutorial", 5, 3) AS ExtractString; Definition and Usage The MID() function extracts a substring…

2 min
Read lesson →
Lesson 102visual

MySQL POSITION() Function

Example Search for "3" in string "W3Schools.com", and return position: SELECT POSITION("3" IN "W3Schools.com") AS MatchPosition; Definition and Usage The POSITION() function returns the position of t…

2 min
Read lesson →
Lesson 103visual

MySQL REPEAT() Function

Example Repeat a string 3 times: SELECT REPEAT("SQL Tutorial", 3); Definition and Usage The REPEAT() function repeats a string as many times as specified. Syntax REPEAT( string, number ) Parameter Va…

2 min
Read lesson →
Lesson 104visual

MySQL REPLACE() Function

Example Replace "SQL" with "HTML": SELECT REPLACE("SQL Tutorial", "SQL", "HTML"); Definition and Usage The REPLACE() function replaces all occurrences of a substring within a string, with a new subst…

2 min
Read lesson →
Lesson 105visual

MySQL REVERSE() Function

Example Reverse a string: SELECT REVERSE("SQL Tutorial"); Definition and Usage The REVERSE() function reverses a string and returns the result. Syntax REVERSE( string ) Parameter Values Parameter Des…

2 min
Read lesson →
Lesson 106visual

MySQL RIGHT() Function

MySQL RIGHT() Function

2 min
Read lesson →
Lesson 107visual

MySQL RPAD() Function

Example Right-pad the string with "ABC", to a total length of 20: SELECT RPAD("SQL Tutorial", 20, "ABC"); Definition and Usage The RPAD() function right-pads a string with another string, to a certai…

2 min
Read lesson →
Lesson 108visual

MySQL RTRIM() Function

Example Remove trailing spaces from a string: SELECT RTRIM("SQL Tutorial ") AS RightTrimmedString; Definition and Usage The RTRIM() function removes trailing spaces from a string. Syntax RTRIM( strin…

2 min
Read lesson →
Lesson 109visual

MySQL SPACE() Function

Example Return a string with 10 space characters: SELECT SPACE(10); Definition and Usage The SPACE() function returns a string of the specified number of space characters. Syntax SPACE( number ) Para…

2 min
Read lesson →
Lesson 110visual

MySQL STRCMP() Function

Example Compare two strings: SELECT STRCMP("SQL Tutorial", "SQL Tutorial"); Definition and Usage The STRCMP() function compares two strings. Syntax STRCMP( string1, string2 ) Parameter Values Paramet…

2 min
Read lesson →
Lesson 111visual

MySQL SUBSTR() Function

Example Extract a substring from a string (start at position 5, extract 3 characters): SELECT SUBSTR("SQL Tutorial", 5, 3) AS ExtractString; Definition and Usage The SUBSTR() function extracts a subs…

2 min
Read lesson →
Lesson 112visual

MySQL SUBSTRING() Function

Example Extract a substring from a string (start at position 1, extract 3 characters): SELECT SUBSTRING("SQL Tutorial", 1, 3) AS ExtractString; Definition and Usage The SUBSTRING() function extracts…

2 min
Read lesson →
Lesson 113visual

MySQL SUBSTRING_INDEX() Function

Example Return a substring of a string before a specified number of delimiter occurs: SELECT SUBSTRING_INDEX("www.w3schools.com", ".", 1); Definition and Usage The SUBSTRING_INDEX() function returns…

2 min
Read lesson →
Lesson 114visual

MySQL TRIM() Function

Example Remove leading and trailing spaces from a string: SELECT TRIM(' SQL Tutorial ') AS TrimmedString; Definition and Usage The TRIM() function removes leading and trailing spaces from a string. S…

2 min
Read lesson →
Lesson 115visual

MySQL UCASE() Function

Example Convert the text to upper-case: SELECT UCASE("SQL Tutorial is FUN!"); Definition and Usage The UCASE() function converts a string to upper-case. Note: This function is equal to the UPPER() fu…

2 min
Read lesson →
Lesson 116visual

MySQL UPPER() Function

Example Convert the text to upper-case: SELECT UPPER("SQL Tutorial is FUN!"); Definition and Usage The UPPER() function converts a string to upper-case. Note: This function is equal to the UCASE() fu…

2 min
Read lesson →
Lesson 117visual

MySQL ABS() Function

Example Return the absolute value of a number: SELECT ABS(-243.5); Definition and Usage The ABS() function returns the absolute (positive) value of a number. Syntax ABS( number ) Parameter Values Par…

2 min
Read lesson →
Lesson 118visual

MySQL ACOS() Function

Example Return the arc cosine of a number: SELECT ACOS(0.25); Definition and Usage The ACOS() function returns the arc cosine of a number. The specified number must be between -1 to 1, otherwise this…

2 min
Read lesson →
Lesson 119visual

MySQL ASIN() Function

Example Return the arc sine of a number: SELECT ASIN(0.25); Definition and Usage The ASIN() function returns the arc sine of a number. The specified number must be between -1 to 1, otherwise this fun…

2 min
Read lesson →
Lesson 120visual

MySQL ATAN() Function

Example Return the arc tangent of a number: SELECT ATAN(2.5); Definition and Usage The ATAN() function returns the arc tangent of one or two numbers. Syntax ATAN( number ) OR: ATAN( a, b ) Parameter…

2 min
Read lesson →
Lesson 121visual

MySQL ATAN2() Function

Example Return the arc tangent of two values: SELECT ATAN2(0.50, 1); Definition and Usage The ATAN2() function returns the arc tangent of two numbers. Syntax ATAN2( a, b ) Parameter Values Parameter…

2 min
Read lesson →
Lesson 122visual

MySQL AVG() Function

Example Return the average value for the "Price" column in the "Products" table: SELECT AVG(Price) AS AveragePrice FROM Products; Definition and Usage The AVG() function returns the average value of…

2 min
Read lesson →
Lesson 123visual

MySQL CEIL() Function

Example Return the smallest integer value that is greater than or equal to 25.75: SELECT CEIL(25.75); Definition and Usage The CEIL() function returns the smallest integer value that is bigger than o…

2 min
Read lesson →
Lesson 124visual

MySQL CEILING() Function

Example Return the smallest integer value that is greater than or equal to 25.75: SELECT CEILING(25.75); Definition and Usage The CEILING() function returns the smallest integer value that is bigger…

2 min
Read lesson →
Lesson 125visual

MySQL COS() Function

Example Return the cosine of a number: SELECT COS(2); Definition and Usage The COS() function returns the cosine of a number. Syntax COS( number ) Parameter Values Parameter Description number Requir…

2 min
Read lesson →
Lesson 126visual

MySQL COT() Function

Example Return the cotangent of a number: SELECT COT(6); Definition and Usage The COT() function returns the cotangent of a number. Syntax COT( number ) Parameter Values Parameter Description number…

2 min
Read lesson →
Lesson 127visual

MySQL COUNT() Function

Example Return the number of products in the "Products" table: SELECT COUNT(ProductID) AS NumberOfProducts FROM Products; Definition and Usage The COUNT() function returns the number of records retur…

2 min
Read lesson →
Lesson 128visual

MySQL DEGREES() Function

Example Convert the radian value into degrees: SELECT DEGREES(1.5); Definition and Usage The DEGREES() function converts a value in radians to degrees. Note: See also the RADIANS() and PI() functions…

2 min
Read lesson →
Lesson 129visual

MySQL DIV Function

Example Integer division (10/5): SELECT 10 DIV 5; Definition and Usage The DIV function is used for integer division (x is divided by y). An integer value is returned. Syntax x DIV y Parameter Values…

2 min
Read lesson →
Lesson 130visual

MySQL EXP() Function

MySQL EXP() Function

2 min
Read lesson →
Lesson 131visual

MySQL FLOOR() Function

Example Return the largest integer value that is less than or equal to 25.75: SELECT FLOOR(25.75); Definition and Usage The FLOOR() function returns the largest integer value that is smaller than or…

2 min
Read lesson →
Lesson 132visual

MySQL GREATEST() Function

Example Return the greatest value of the list of arguments: SELECT GREATEST(3, 12, 34, 8, 25); Definition and Usage The GREATEST() function returns the greatest value of the list of arguments. Note:…

2 min
Read lesson →
Lesson 133visual

MySQL LEAST() Function

Example Return the smallest value of the list of arguments: SELECT LEAST(3, 12, 34, 8, 25); Definition and Usage The LEAST() function returns the smallest value of the list of arguments. Note: See al…

2 min
Read lesson →
Lesson 134visual

MySQL LN() Function

Example Return the natural logarithm of 2: SELECT LN(2); Definition and Usage The LN() function returns the natural logarithm of a number. Note: See also the LOG() and EXP() functions. Syntax LN( num…

2 min
Read lesson →
Lesson 135visual

MySQL LOG() Function

Example Return the natural logarithm of 2: SELECT LOG(2); Definition and Usage The LOG() function returns the natural logarithm of a specified number, or the logarithm of the number to the specified…

2 min
Read lesson →
Lesson 136visual

MySQL LOG10() Function

Example Return the base-10 logarithm of 2: SELECT LOG10(2); Definition and Usage The LOG10() function returns the natural logarithm of a number to base-10. Note: See also the LOG() function. Syntax L…

2 min
Read lesson →
Lesson 137visual

MySQL LOG2() Function

Example Return the base-2 logarithm of 6: SELECT LOG2(6); Definition and Usage The LOG2() function returns the natural logarithm of a number to base-2. Note: See also the LOG() function. Syntax LOG2(…

2 min
Read lesson →
Lesson 138visual

MySQL MAX() Function

Example Find the price of the most expensive product in the "Products" table: SELECT MAX(Price) AS LargestPrice FROM Products; Definition and Usage The MAX() function returns the maximum value in a s…

2 min
Read lesson →
Lesson 139visual

MySQL MIN() Function

Example Find the price of the cheapest product in the "Products" table: SELECT MIN(Price) AS SmallestPrice FROM Products; Definition and Usage The MIN() function returns the minimum value in a set of…

2 min
Read lesson →
Lesson 140visual

MySQL MOD() Function

Example Return the remainder of 18/4: SELECT MOD(18, 4); Definition and Usage The MOD() function returns the remainder of a number divided by another number. Syntax MOD( x, y ) OR: x MOD y OR: x % y…

2 min
Read lesson →
Lesson 141visual

MySQL PI() Function

Example Return the value of PI: SELECT PI(); Definition and Usage The PI() function returns the value of PI. Note: See also the DEGREES() and RADIANS() functions. Syntax PI() Technical Details Works…

2 min
Read lesson →
Lesson 142visual

MySQL POW() Function

Example Return 4 raised to the second power: SELECT POW(4, 2); Definition and Usage The POW() function returns the value of a number raised to the power of another number. Note: This function is equa…

2 min
Read lesson →
Lesson 143visual

MySQL POWER() Function

Example Return 4 raised to the second power: SELECT POWER(4, 2); Definition and Usage The POWER() function returns the value of a number raised to the power of another number. Note: This function is…

2 min
Read lesson →
Lesson 144visual

MySQL RADIANS() Function

Example Convert a degree value into radians: SELECT RADIANS(180); Definition and Usage The RADIANS() function converts a degree value into radians. Note: See also the DEGREES() and PI() functions. Sy…

2 min
Read lesson →
Lesson 145visual

MySQL RAND() Function

Example Return a random decimal number (no seed value - so it returns a completely random number >= 0 and <1): SELECT RAND(); Definition and Usage The RAND() function returns a random number between…

2 min
Read lesson →
Lesson 146visual

MySQL ROUND() Function

Example Round the number to 2 decimal places: SELECT ROUND(135.375, 2); Definition and Usage The ROUND() function rounds a number to a specified number of decimal places. Note: See also the FLOOR(),…

2 min
Read lesson →
Lesson 147visual

MySQL SIGN() Function

Example Return the sign of a number: SELECT SIGN(255.5); Definition and Usage The SIGN() function returns the sign of a number. This function will return one of the following: If number > 0, it retur…

2 min
Read lesson →
Lesson 148visual

MySQL SIN() Function

Example Return the sine of a number: SELECT SIN(2); Definition and Usage The SIN() function returns the sine of a number. Syntax SIN( number ) Parameter Values Parameter Description number Required.…

2 min
Read lesson →
Lesson 149visual

MySQL SQRT() Function

Example Return the square root of a number: SELECT SQRT(64); Definition and Usage The SQRT() function returns the square root of a number. Syntax SQRT( number ) Parameter Values Parameter Description…

2 min
Read lesson →
Lesson 150visual

MySQL SUM() Function

Example Return the sum of the "Quantity" field in the "OrderDetails" table: SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails; Definition and Usage The SUM() function calculates the sum of…

2 min
Read lesson →
Lesson 151visual

MySQL TAN() Function

Example Return the tangent of a number: SELECT TAN(1.75); Definition and Usage The TAN() function returns the tangent of a number. Syntax TAN( number ) Parameter Values Parameter Description number R…

2 min
Read lesson →
Lesson 152visual

MySQL TRUNCATE() Function

Example Return a number truncated to 2 decimal places: SELECT TRUNCATE(135.375, 2); Definition and Usage The TRUNCATE() function truncates a number to the specified number of decimal places. Note: Se…

2 min
Read lesson →
Lesson 153visual

MySQL ADDDATE() Function

Example Add 10 days to a date and return the date: SELECT ADDDATE("2017-06-15", INTERVAL 10 DAY); Definition and Usage The ADDDATE() function adds a time/date interval to a date and then returns the…

2 min
Read lesson →
Lesson 154visual

MySQL ADDTIME() Function

Example Add 2 seconds to a time and return the datetime: SELECT ADDTIME("2017-06-15 09:34:21", "2"); Definition and Usage The ADDTIME() function adds a time interval to a time/datetime and then retur…

2 min
Read lesson →
Lesson 155visual

MySQL CURDATE() Function

Example Return the current date: SELECT CURDATE(); Definition and Usage The CURDATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric).…

2 min
Read lesson →
Lesson 156visual

MySQL CURRENT_DATE() Function

Example Return the current date: SELECT CURRENT_DATE(); Definition and Usage The CURRENT_DATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (…

2 min
Read lesson →
Lesson 157visual

MySQL CURRENT_TIME() Function

Example Return current time: SELECT CURRENT_TIME(); Definition and Usage The CURRENT_TIME() function returns the current time. Note: The time is returned as "HH-MM-SS" (string) or as HHMMSS.uuuuuu (n…

2 min
Read lesson →
Lesson 158visual

MySQL CURRENT_TIMESTAMP() Function

Example Return the current date and time: SELECT CURRENT_TIMESTAMP(); Definition and Usage The CURRENT_TIMESTAMP() function returns the current date and time. Note: The date and time is returned as "…

2 min
Read lesson →
Lesson 159visual

MySQL CURTIME() Function

Example Return current time: SELECT CURTIME(); Definition and Usage The CURTIME() function returns the current time. Note: The time is returned as "HH-MM-SS" (string) or as HHMMSS.uuuuuu (numeric). N…

2 min
Read lesson →
Lesson 160visual

MySQL DATE() Function

Example Extract the date part: SELECT DATE("2017-06-15"); Definition and Usage The DATE() function extracts the date part from a datetime expression. Syntax DATE( expression ) Parameter Values Parame…

2 min
Read lesson →
Lesson 161visual

MySQL DATEDIFF() Function

Example Return the number of days between two date values: SELECT DATEDIFF("2017-06-25", "2017-06-15"); Definition and Usage The DATEDIFF() function returns the number of days between two date values…

2 min
Read lesson →
Lesson 162visual

MySQL DATE_ADD() Function

Example Add 10 days to a date and return the date: SELECT DATE_ADD("2017-06-15", INTERVAL 10 DAY); Definition and Usage The DATE_ADD() function adds a time/date interval to a date and then returns th…

2 min
Read lesson →
Lesson 163visual

MySQL DATE_FORMAT() Function

Example Format a date: SELECT DATE_FORMAT("2017-06-15", "%Y"); Definition and Usage The DATE_FORMAT() function formats a date as specified. Syntax DATE_FORMAT( date, format ) Parameter Values Paramet…

2 min
Read lesson →
Lesson 164visual

MySQL DATE_SUB() Function

Example Subtract 10 days from a date and return the date: SELECT DATE_SUB("2017-06-15", INTERVAL 10 DAY); Definition and Usage The DATE_SUB() function subtracts a time/date interval from a date and t…

2 min
Read lesson →
Lesson 165visual

MySQL DAY() Function

Example Return the day of the month for a date: SELECT DAY("2017-06-15"); Definition and Usage The DAY() function returns the day of the month for a given date (a number from 1 to 31). Note: This fun…

2 min
Read lesson →
Lesson 166visual

MySQL DAYNAME() Function

Example Return the weekday name for a date: SELECT DAYNAME("2017-06-15"); Definition and Usage The DAYNAME() function returns the weekday name for a given date. Syntax DAYNAME( date ) Parameter Value…

2 min
Read lesson →
Lesson 167visual

MySQL DAYOFMONTH() Function

Example Return the day of the month for a date: SELECT DAYOFMONTH("2017-06-15"); Definition and Usage The DAYOFMONTH() function returns the day of the month for a given date (a number from 1 to 31).…

2 min
Read lesson →
Lesson 168visual

MySQL DAYOFWEEK() Function

Example Return the weekday index for a date: SELECT DAYOFWEEK("2017-06-15"); Definition and Usage The DAYOFWEEK() function returns the weekday index for a given date (a number from 1 to 7). Note: 1=S…

2 min
Read lesson →
Lesson 169visual

MySQL DAYOFYEAR() Function

Example Return the day of the year for a date: SELECT DAYOFYEAR("2017-06-15"); Definition and Usage The DAYOFYEAR() function returns the day of the year for a given date (a number from 1 to 366). Syn…

2 min
Read lesson →
Lesson 170visual

MySQL EXTRACT() Function

Example Extract the month from a date: SELECT EXTRACT(MONTH FROM "2017-06-15"); Definition and Usage The EXTRACT() function extracts a part from a given date. Syntax EXTRACT( part FROM date ) Paramet…

2 min
Read lesson →
Lesson 171visual

MySQL FROM_DAYS() Function

Example Return a date from a numeric representation of the day: SELECT FROM_DAYS(685467); Definition and Usage The FROM_DAYS() function returns a date from a numeric datevalue. The FROM_DAYS() functi…

2 min
Read lesson →
Lesson 172visual

MySQL HOUR() Function

Example Return the hour part of a datetime: SELECT HOUR("2017-06-20 09:34:00"); Definition and Usage The HOUR() function returns the hour part for a given date (from 0 to 838). Syntax HOUR( datetime…

2 min
Read lesson →
Lesson 173visual

MySQL LAST_DAY() Function

Example Extract the last day of the month for the given date: SELECT LAST_DAY("2017-06-20"); Definition and Usage The LAST_DAY() function extracts the last day of the month for a given date. Syntax L…

2 min
Read lesson →
Lesson 174visual

MySQL LOCALTIME() Function

Example Return current date and time: SELECT LOCALTIME(); Definition and Usage The LOCALTIME() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS"…

2 min
Read lesson →
Lesson 175visual

MySQL LOCALTIMESTAMP() Function

Example Return current date and time: SELECT LOCALTIMESTAMP(); Definition and Usage The LOCALTIMESTAMP() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD…

2 min
Read lesson →
Lesson 176visual

MySQL MAKEDATE() Function

Example Create and return a date based on a year and a number of days value: SELECT MAKEDATE(2017, 3); Definition and Usage The MAKEDATE() function creates and returns a date based on a year and a nu…

2 min
Read lesson →
Lesson 177visual

MySQL MAKETIME() Function

Example Create and return a time value based on an hour, minute, and second value: SELECT MAKETIME(11, 35, 4); Definition and Usage The MAKETIME() function creates and returns a time based on an hour…

2 min
Read lesson →
Lesson 178visual

MySQL MICROSECOND() Function

Example Return the microsecond part of a datetime: SELECT MICROSECOND("2017-06-20 09:34:00.000023"); Definition and Usage The MICROSECOND() function returns the microsecond part of a time/datetime (f…

2 min
Read lesson →
Lesson 179visual

MySQL MINUTE() Function

Example Return the minute part of a datetime value: SELECT MINUTE("2017-06-20 09:34:00"); Definition and Usage The MINUTE() function returns the minute part of a time/datetime (from 0 to 59). Syntax…

2 min
Read lesson →
Lesson 180visual

MySQL MONTH() Function

Example Return the month part of a date: SELECT MONTH("2017-06-15"); Definition and Usage The MONTH() function returns the month part for a given date (a number from 1 to 12). Syntax MONTH( date ) Pa…

2 min
Read lesson →
Lesson 181visual

MySQL MONTHNAME() Function

Example Return the name of the month for a date: SELECT MONTHNAME("2017-06-15"); Definition and Usage The MONTHNAME() function returns the name of the month for a given date. Syntax MONTHNAME( date )…

2 min
Read lesson →
Lesson 182visual

MySQL NOW() Function

Example Return current date and time: SELECT NOW(); Definition and Usage The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or…

2 min
Read lesson →
Lesson 183visual

MySQL PERIOD_ADD() Function

Example Add a specified number of months to a period: SELECT PERIOD_ADD(201703, 5); Definition and Usage The PERIOD_ADD() function adds a specified number of months to a period. The PERIOD_ADD() func…

2 min
Read lesson →
Lesson 184visual

MySQL PERIOD_DIFF() Function

Example Return the difference between two periods: SELECT PERIOD_DIFF(201710, 201703); Definition and Usage The PERIOD_DIFF() function returns the difference between two periods. The result will be i…

2 min
Read lesson →
Lesson 185visual

MySQL QUARTER() Function

Example Return the quarter of the year for the date: SELECT QUARTER("2017-06-15"); Definition and Usage The QUARTER() function returns the quarter of the year for a given date value (a number from 1…

2 min
Read lesson →
Lesson 186visual

MySQL SECOND() Function

Example Return the seconds part of a datetime value: SELECT SECOND("2017-06-20 09:34:00.000023"); Definition and Usage The SECOND() function returns the seconds part of a time/datetime (from 0 to 59)…

2 min
Read lesson →
Lesson 187visual

MySQL SEC_TO_TIME() Function

Example Return a time value based on a specified seconds value: SELECT SEC_TO_TIME(1); Definition and Usage The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified…

2 min
Read lesson →
Lesson 188visual

MySQL STR_TO_DATE() Function

Example Return a date based on a string and a format: SELECT STR_TO_DATE("August 10 2017", "%M %d %Y"); Definition and Usage The STR_TO_DATE() function returns a date based on a string and a format.…

2 min
Read lesson →
Lesson 189visual

MySQL SUBDATE() Function

Example Subtract 10 days from a date and return the date: SELECT SUBDATE("2017-06-15", INTERVAL 10 DAY); Definition and Usage The SUBDATE() function subtracts a time/date interval from a date and the…

2 min
Read lesson →
Lesson 190visual

MySQL SUBTIME() Function

Example Subtract 5.000001 seconds and return the datetime: SELECT SUBTIME("2017-06-15 10:24:21.000004", "5.000001"); Definition and Usage The SUBTIME() function subtracts time from a time/datetime ex…

2 min
Read lesson →
Lesson 191visual

MySQL SYSDATE() Function

Example Return the current date and time: SELECT SYSDATE(); Definition and Usage The SYSDATE() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH:MM:SS"…

2 min
Read lesson →
Lesson 192visual

MySQL TIME() Function

Example Extract the time part from a time expression: SELECT TIME("19:30:10"); Definition and Usage The TIME() function extracts the time part from a given time/datetime. Note: This function returns…

2 min
Read lesson →
Lesson 193visual

MySQL TIME_FORMAT() Function

Example Format a time: SELECT TIME_FORMAT("19:30:10", "%H %i %s"); Definition and Usage The TIME_FORMAT() function formats a time by a specified format. Syntax TIME_FORMAT( time, format ) Parameter V…

2 min
Read lesson →
Lesson 194visual

MySQL TIME_TO_SEC() Function

Example Convert a time value into seconds: SELECT TIME_TO_SEC("19:30:10"); Definition and Usage The TIME_TO_SEC() function converts a time value into seconds. Syntax TIME_TO_SEC( time ) Parameter Val…

2 min
Read lesson →
Lesson 195visual

MySQL TIMEDIFF() Function

Example Return the difference between two time expressions: SELECT TIMEDIFF("13:10:11", "13:10:10"); Definition and Usage The TIMEDIFF() function returns the difference between two time/datetime expr…

2 min
Read lesson →
Lesson 196visual

MySQL TIMESTAMP() Function

Example Return a datetime value based on the arguments: SELECT TIMESTAMP("2017-07-23", "13:10:11"); Definition and Usage The TIMESTAMP() function returns a datetime value based on a date or datetime…

2 min
Read lesson →
Lesson 197visual

MySQL TO_DAYS() Function

Example Return the number of days between the date and year 0: SELECT TO_DAYS("2017-06-20"); Definition and Usage The TO_DAYS() function returns the number of days between a date and year 0 (date "00…

2 min
Read lesson →
Lesson 198visual

MySQL WEEK() Function

Example Return the week number for a date: SELECT WEEK("2017-06-15"); Definition and Usage The WEEK() function returns the week number for a given date (a number from 0 to 53). Syntax WEEK( date, fir…

2 min
Read lesson →
Lesson 199visual

MySQL WEEKDAY() Function

Example Return the weekday number for a date: SELECT WEEKDAY("2017-06-15"); Definition and Usage The WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 =…

2 min
Read lesson →
Lesson 200visual

MySQL WEEKOFYEAR() Function

MySQL WEEKOFYEAR() Function

2 min
Read lesson →
Lesson 201visual

MySQL YEAR() Function

Example Return the year part of a date: SELECT YEAR("2017-06-15"); Definition and Usage The YEAR() function returns the year part for a given date (a number from 1000 to 9999). Syntax YEAR( date ) Pa…

2 min
Read lesson →
Lesson 202visual

MySQL YEARWEEK() Function

Example Return the year and week number for a date: SELECT YEARWEEK("2017-06-15"); Definition and Usage The YEARWEEK() function returns the year and week number (a number from 0 to 53) for a given da…

2 min
Read lesson →
Lesson 203visual

MySQL BIN() Function

Example Return a binary representation of 15: SELECT BIN(15); Definition and Usage The BIN() function returns a binary representation of a number, as a string value. Syntax BIN( number ) Parameter Va…

2 min
Read lesson →
Lesson 204visual

MySQL BINARY Function

Example Convert a value to a binary string: SELECT BINARY "W3Schools.com"; Definition and Usage The BINARY function converts a value to a binary string. This function is equivalent to using CAST(valu…

2 min
Read lesson →
Lesson 205visual

MySQL CASE Function

Example Go through conditions and return a value when the first condition is met: SELECT OrderID, Quantity, CASE WHEN Quantity > 30 THEN "The quantity is greater than 30" WHEN Quantity = 30 THEN "The…

2 min
Read lesson →
Lesson 206visual

MySQL CAST() Function

MySQL CAST() Function

2 min
Read lesson →
Lesson 207visual

MySQL COALESCE() Function

Example Return the first non-null value in a list: SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com'); Definition and Usage The COALESCE() function returns the first non-null val…

2 min
Read lesson →
Lesson 208visual

MySQL CONNECTION_ID() Function

Example Return the unique connection ID for the current connection: SELECT CONNECTION_ID(); Definition and Usage The CONNECTION_ID() function returns the unique connection ID for the current connecti…

2 min
Read lesson →
Lesson 209visual

MySQL CONV() Function

MySQL CONV() Function

2 min
Read lesson →
Lesson 210visual

MySQL CONVERT() Function

MySQL CONVERT() Function

2 min
Read lesson →
Lesson 211visual

MySQL CURRENT_USER() Function

MySQL CURRENT_USER() Function

2 min
Read lesson →
Lesson 212visual

MySQL DATABASE() Function

Example Return the name of the current (default) database: SELECT DATABASE(); Definition and Usage The DATABASE() function returns the name of the current database. If there is no current database, t…

2 min
Read lesson →
Lesson 213visual

MySQL IF() Function

Example Return "YES" if the condition is TRUE, or "NO" if the condition is FALSE: SELECT IF(500<1000, "YES", "NO"); Definition and Usage The IF() function returns a value if a condition is TRUE, or a…

2 min
Read lesson →
Lesson 214visual

MySQL IFNULL() Function

Example Return the specified value IF the expression is NULL, otherwise return the expression: SELECT IFNULL(NULL, "W3Schools.com"); Definition and Usage The IFNULL() function returns a specified val…

2 min
Read lesson →
Lesson 215visual

MySQL ISNULL() Function

Example Test whether an expression is NULL: SELECT ISNULL(NULL); Definition and Usage The ISNULL() function returns 1 or 0 depending on whether an expression is NULL. If expression is NULL, this func…

2 min
Read lesson →
Lesson 216visual

MySQL LAST_INSERT_ID() Function

Example Return the AUTO_INCREMENT id of the last row that has been inserted in a table: SELECT LAST_INSERT_ID(); Definition and Usage The LAST_INSERT_ID() function returns the AUTO_INCREMENT id of th…

2 min
Read lesson →
Lesson 217visual

MySQL NULLIF() Function

Example Compare two expressions: SELECT NULLIF(25, 25); Definition and Usage The NULLIF() function compares two expressions and returns NULL if they are equal. Otherwise, the first expression is retu…

2 min
Read lesson →
Lesson 218visual

MySQL SESSION_USER() Function

Example Return the current user name and host name for the MySQL connection: SELECT SESSION_USER(); Definition and Usage The SESSION_USER() function returns the current user name and host name for th…

2 min
Read lesson →
Lesson 219visual

MySQL SYSTEM_USER() Function

Example Return the current user name and host name for the MySQL connection: SELECT SYSTEM_USER(); Definition and Usage The SYSTEM_USER() function returns the current user name and host name for the…

2 min
Read lesson →
Lesson 220visual

MySQL USER() Function

MySQL USER() Function

2 min
Read lesson →
Lesson 221visual

MySQL VERSION() Function

Example Return the current version of the MySQL database: SELECT VERSION(); Definition and Usage The VERSION() function returns the current version of the MySQL database, as a string. Syntax VERSION(…

2 min
Read lesson →
Lesson 222visual

SQL Server Functions

SQL Server has many built-in functions. This reference contains string, numeric, date, conversion, and some advanced functions in SQL Server. SQL Server String Functions Function Description ASCII Re…

5 min
Read lesson →
Lesson 223visual

SQL Server ASCII() Function

Example Return the ASCII value of the first character in "CustomerName": SELECT ASCII(CustomerName) AS NumCodeOfFirstChar FROM Customers; Definition and Usage The ASCII() function returns the ASCII v…

2 min
Read lesson →
Lesson 224visual

SQL Server CHAR() Function

Example Return the character based on the number code 65: SELECT CHAR(65) AS CodeToCharacter; Definition and Usage The CHAR() function returns the character based on the ASCII code. Syntax CHAR( code…

2 min
Read lesson →
Lesson 225visual

SQL Server CHARINDEX() Function

Example Search for "t" in string "Customer", and return position: SELECT CHARINDEX('t', 'Customer') AS MatchPosition; Definition and Usage The CHARINDEX() function searches for a substring in a strin…

2 min
Read lesson →
Lesson 226visual

SQL Server CONCAT() Function

Example Add two strings together: SELECT CONCAT('W3Schools', '.com'); Definition and Usage The CONCAT() function adds two or more strings together. Note: See also Concat with the + operator and CONCA…

2 min
Read lesson →
Lesson 227visual

SQL Server Concat With +

Example Add 2 strings together: SELECT 'W3Schools' + '.com'; Definition and Usage The + operator allows you to add two or more strings together. Note: See also the CONCAT() and CONCAT_WS() functions.…

2 min
Read lesson →
Lesson 228visual

SQL Server CONCAT_WS() Function

Example Add strings together. Use '.' to separate the concatenated string values: SELECT CONCAT_WS('.', 'www', 'W3Schools', 'com'); Definition and Usage The CONCAT_WS() function adds two or more stri…

2 min
Read lesson →
Lesson 229visual

SQL Server DATALENGTH() Function

SQL Server DATALENGTH() Function

2 min
Read lesson →
Lesson 230visual

SQL Server DIFFERENCE() Function

SQL Server DIFFERENCE() Function

2 min
Read lesson →
Lesson 231visual

SQL Server FORMAT() Function

Example Format a date: DECLARE @d DATETIME = '12/01/2018'; SELECT FORMAT (@d, 'd', 'en-US') AS 'US English Result', FORMAT (@d, 'd', 'no') AS 'Norwegian Result', FORMAT (@d, 'd', 'zu') AS 'Zulu Resul…

2 min
Read lesson →
Lesson 232visual

SQL Server LEFT() Function

Example Extract 3 characters from a string (starting from left): SELECT LEFT('SQL Tutorial', 3) AS ExtractString; Definition and Usage The LEFT() function extracts a number of characters from a strin…

2 min
Read lesson →
Lesson 233visual

SQL Server LEN() Function

SQL Server LEN() Function

2 min
Read lesson →
Lesson 234visual

SQL Server LOWER() Function

Example Convert the text to lower-case: SELECT LOWER('SQL Tutorial is FUN!'); Definition and Usage The LOWER() function converts a string to lower-case. Note: Also look at the UPPER() function. Synta…

2 min
Read lesson →
Lesson 235visual

SQL Server LTRIM() Function

Example Remove leading spaces from a string: SELECT LTRIM(' SQL Tutorial') AS LeftTrimmedString; Definition and Usage The LTRIM() function removes leading spaces from a string. Note: Also look at the…

2 min
Read lesson →
Lesson 236visual

SQL Server NCHAR() Function

Example Return the Unicode character based on the number code 65: SELECT NCHAR(65) AS NumberCodeToUnicode; Definition and Usage The NCHAR() function returns the Unicode character based on the number…

2 min
Read lesson →
Lesson 237visual

SQL Server PATINDEX() Function

Example Return the position of a pattern in a string: SELECT PATINDEX('%schools%', 'W3Schools.com'); Definition and Usage The PATINDEX() function returns the position of a pattern in a string. If the…

2 min
Read lesson →
Lesson 238visual

SQL Server QUOTENAME() Function

Example Return a Unicode string with bracket delimiters (default): SELECT QUOTENAME('abcdef'); Definition and Usage The QUOTENAME() function returns a Unicode string with delimiters added to make the…

2 min
Read lesson →
Lesson 239visual

SQL Server REPLACE() Function

SQL Server REPLACE() Function

2 min
Read lesson →
Lesson 240visual

SQL Server REPLICATE() Function

Example Repeat a string: SELECT REPLICATE('SQL Tutorial', 5); Definition and Usage The REPLICATE() function repeats a string a specified number of times. Syntax REPLICATE( string, integer ) Parameter…

2 min
Read lesson →
Lesson 241visual

SQL Server REVERSE() Function

Example Reverse a string: SELECT REVERSE('SQL Tutorial'); Definition and Usage The REVERSE() function reverses a string and returns the result. Syntax REVERSE( string ) Parameter Values Parameter Des…

2 min
Read lesson →
Lesson 242visual

SQL Server RIGHT() Function

Example Extract 3 characters from a string (starting from right): SELECT RIGHT('SQL Tutorial', 3) AS ExtractString; Definition and Usage The RIGHT() function extracts a number of characters from a st…

2 min
Read lesson →
Lesson 243visual

SQL Server RTRIM() Function

Example Remove trailing spaces from a string: SELECT RTRIM('SQL Tutorial ') AS RightTrimmedString; Definition and Usage The RTRIM() function removes trailing spaces from a string. Note: Also look at…

2 min
Read lesson →
Lesson 244visual

SQL Server SOUNDEX() Function

SQL Server SOUNDEX() Function

2 min
Read lesson →
Lesson 245visual

SQL Server SPACE() Function

Example Return a string with 10 spaces: SELECT SPACE(10); Definition and Usage The SPACE() function returns a string of the specified number of space characters. SPACE( number ) Parameter Values Para…

2 min
Read lesson →
Lesson 246visual

SQL Server STR() Function

Example Return a number as a string: SELECT STR(185); Definition and Usage The STR() function returns a number as a string. Syntax STR( number, length, decimals ) Parameter Values Parameter Descripti…

2 min
Read lesson →
Lesson 247visual

SQL Server STUFF() Function

SQL Server STUFF() Function

2 min
Read lesson →
Lesson 248visual

SQL Server SUBSTRING() Function

Example Extract 3 characters from a string, starting in position 1: SELECT SUBSTRING('SQL Tutorial', 1, 3) AS ExtractString; Definition and Usage The SUBSTRING() function extracts some characters fro…

2 min
Read lesson →
Lesson 249visual

SQL Server TRANSLATE() Function

Example Return the string from the first argument AFTER the characters specified in the second argument are translated into the characters specified in the third argument: SELECT TRANSLATE('Monday',…

2 min
Read lesson →
Lesson 250visual

SQL Server TRIM() Function

Example Remove leading and trailing spaces from a string: SELECT TRIM(' SQL Tutorial! ') AS TrimmedString; Definition and Usage The TRIM() function removes the space character OR other specified char…

2 min
Read lesson →
Lesson 251visual

SQL Server UNICODE() Function

Example Return an integer value (the Unicode value), for the first character of the input expression: SELECT UNICODE('Atlanta'); Definition and Usage The UNICODE() function returns an integer value (…

2 min
Read lesson →
Lesson 252visual

SQL Server UPPER() Function

Example Convert the text to upper-case: SELECT UPPER('SQL Tutorial is FUN!'); Definition and Usage The UPPER() function converts a string to upper-case. Note: Also look at the LOWER() function. Synta…

2 min
Read lesson →
Lesson 253visual

SQL Server ABS() Function

Example Return the absolute value of a number: SELECT Abs(-243.5) AS AbsNum; Definition and Usage The ABS() function returns the absolute value of a number. Syntax ABS( number ) Parameter Values Para…

2 min
Read lesson →
Lesson 254visual

SQL Server ACOS() Function

Example Return the arc cosine of a number: SELECT ACOS(0.25); Definition and Usage The ACOS() function returns the arc cosine of a number. The specified number must be between -1 to 1, otherwise this…

2 min
Read lesson →
Lesson 255visual

SQL Server ASIN() Function

Example Return the arc sine of a number: SELECT ASIN(0.25); Definition and Usage The ASIN() function returns the arc sine of a number. The specified number must be between -1 to 1, otherwise this fun…

2 min
Read lesson →
Lesson 256visual

SQL Server ATAN() Function

Example Return the arc tangent of a number: SELECT ATAN(2.5); Definition and Usage The ATAN() function returns the arc tangent of a number. Syntax ATAN( number ) Parameter Values Parameter Descriptio…

2 min
Read lesson →
Lesson 257visual

SQL Server ATN2() Function

Example Return the arc tangent of two values: SELECT ATN2(0.50, 1); Definition and Usage The ATN2() function returns the arc tangent of two numbers. Syntax ATN2( a, b ) Parameter Values Parameter Des…

2 min
Read lesson →
Lesson 258visual

SQL Server AVG() Function

Example Return the average value for the "Price" column in the "Products" table: SELECT AVG(Price) AS AveragePrice FROM Products; Definition and Usage The AVG() function returns the average value of…

2 min
Read lesson →
Lesson 259visual

SQL Server CEILING() Function

SQL Server CEILING() Function

2 min
Read lesson →
Lesson 260visual

SQL Server COUNT() Function

Example Return the number of products in the "Products" table: SELECT COUNT(ProductID) AS NumberOfProducts FROM Products; Definition and Usage The COUNT() function returns the number of records retur…

2 min
Read lesson →
Lesson 261visual

SQL Server COS() Function

Example Return the cosine of a number: SELECT COS(2); Definition and Usage The COS() function returns the cosine of a number. Syntax COS( number ) Parameter Values Parameter Description number Requir…

2 min
Read lesson →
Lesson 262visual

SQL Server COT() Function

Example Return the cotangent of a number: SELECT COT(6); Definition and Usage The COT() function returns the cotangent of a number. Syntax COT( number ) Parameter Values Parameter Description number…

2 min
Read lesson →
Lesson 263visual

SQL Server DEGREES() Function

Example Convert a radian value into degrees: SELECT DEGREES(1.5); Definition and Usage The DEGREES() function converts a value in radians to degrees. Note: See also the RADIANS() and PI() functions.…

2 min
Read lesson →
Lesson 264visual

SQL Server EXP() Function

Example Return e raised to the power of 1: SELECT EXP(1); Definition and Usage The EXP() function returns e raised to the power of a specified number. The constant e (2.718281...), is the base of nat…

2 min
Read lesson →
Lesson 265visual

SQL Server FLOOR() Function

SQL Server FLOOR() Function

2 min
Read lesson →
Lesson 266visual

SQL Server LOG() Function

Example Return the natural logarithm of 2: SELECT LOG(2); Definition and Usage The LOG() function returns the natural logarithm of a specified number, or the logarithm of the number to the specified…

2 min
Read lesson →
Lesson 267visual

SQL Server LOG10() Function

Example Return the base-10 logarithm of 2: SELECT LOG10(2); Definition and Usage The LOG10() function returns the natural logarithm of a number to base 10. Note: Also look at the LOG() function. Synt…

2 min
Read lesson →
Lesson 268visual

SQL Server MAX() Function

Example Find the price of the most expensive product in the "Products" table: SELECT MAX(Price) AS LargestPrice FROM Products; Definition and Usage The MAX() function returns the maximum value in a s…

2 min
Read lesson →
Lesson 269visual

SQL Server MIN() Function

Example Find the price of the cheapest product in the "Products" table: SELECT MIN(Price) AS SmallestPrice FROM Products; Definition and Usage The MIN() function returns the minimum value in a set of…

2 min
Read lesson →
Lesson 270visual

SQL Server PI() Function

Example Return the value of PI: SELECT PI(); Definition and Usage The PI() function returns the value of PI. Note: Also look at the DEGREES() and RADIANS() functions. Syntax PI() Technical Details Wo…

2 min
Read lesson →
Lesson 271visual

SQL Server POWER() Function

Example Return 4 raised to the second power: SELECT POWER(4, 2); Definition and Usage The POWER() function returns the value of a number raised to the power of another number. Syntax POWER( a, b ) Pa…

2 min
Read lesson →
Lesson 272visual

SQL Server RADIANS() Function

Example Convert a degree value into radians: SELECT RADIANS(180); Definition and Usage The RADIANS() function converts a degree value into radians. Syntax RADIANS( number ) Parameter Values Parameter…

2 min
Read lesson →
Lesson 273visual

SQL Server RAND() Function

Example Return a random decimal number (no seed value - so it returns a completely random number >= 0 and <1): SELECT RAND(); Definition and Usage The RAND() function returns a random number between…

2 min
Read lesson →
Lesson 274visual

SQL Server ROUND() Function

SQL Server ROUND() Function

2 min
Read lesson →
Lesson 275visual

SQL Server SIGN() Function

Example Return the sign of a number: SELECT SIGN(255.5); Definition and Usage The SIGN() function returns the sign of a number. This function will return one of the following: If number > 0, it retur…

2 min
Read lesson →
Lesson 276visual

SQL Server SIN() Function

Example Return the sine of a number: SELECT SIN(2); Definition and Usage The SIN() function returns the sine of a number. Syntax SIN( number ) Parameter Values Parameter Description number Required.…

2 min
Read lesson →
Lesson 277visual

SQL Server SQRT() Function

Example Return the square root of a number: SELECT SQRT(64); Definition and Usage The SQRT() function returns the square root of a number. Syntax SQRT( number ) Parameter Values Parameter Description…

2 min
Read lesson →
Lesson 278visual

SQL Server SQUARE() Function

Example Return the square of a number: SELECT SQUARE(64); Definition and Usage The SQUARE() function returns the square of a number. Syntax SQUARE( number ) Parameter Values Parameter Description num…

2 min
Read lesson →
Lesson 279visual

SQL Server SUM() Function

Example Return the sum of the "Quantity" field in the "OrderDetails" table: SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails; Definition and Usage The SUM() function calculates the sum of…

2 min
Read lesson →
Lesson 280visual

SQL Server TAN() Function

Example Return the tangent of a number: SELECT TAN(1.75); Definition and Usage The TAN() function returns the tangent of a number. Syntax TAN( number ) Parameter Values Parameter Description number R…

2 min
Read lesson →
Lesson 281visual

SQL Server CURRENT_TIMESTAMP Function

SQL Server CURRENT_TIMESTAMP Function

2 min
Read lesson →
Lesson 282visual

SQL Server DATEADD() Function

Example Add one year to a date, then return the date: SELECT DATEADD(year, 1, '2017/08/25') AS DateAdd; Definition and Usage The DATEADD() function adds a time/date interval to a date and then return…

2 min
Read lesson →
Lesson 283visual

SQL Server DATEDIFF() Function

Example Return the difference between two date values, in years: SELECT DATEDIFF(year, '2017/08/25', '2011/08/25') AS DateDiff; Definition and Usage The DATEDIFF() function returns the difference bet…

2 min
Read lesson →
Lesson 284visual

SQL Server DATEFROMPARTS() Function

Example Return a date from its parts: SELECT DATEFROMPARTS(2018, 10, 31) AS DateFromParts; Definition and Usage The DATEFROMPARTS() function returns a date from the specified parts (year, month, and…

2 min
Read lesson →
Lesson 285visual

SQL Server DATENAME() Function

Example Return a specified part of a date: SELECT DATENAME(year, '2017/08/25') AS DatePartString; Definition and Usage The DATENAME() function returns a specified part of a date. This function return…

2 min
Read lesson →
Lesson 286visual

SQL Server DATEPART() Function

Example Return a specified part of a date: SELECT DATEPART(year, '2017/08/25') AS DatePartInt; Definition and Usage The DATEPART() function returns a specified part of a date. This function returns t…

2 min
Read lesson →
Lesson 287visual

SQL Server DAY() Function

Example Return the day of the month for a date: SELECT DAY('2017/08/25') AS DayOfMonth; Definition and Usage The DAY() function returns the day of the month (from 1 to 31) for a specified date. Synta…

2 min
Read lesson →
Lesson 288visual

SQL Server GETDATE() Function

SQL Server GETDATE() Function

2 min
Read lesson →
Lesson 289visual

SQL Server GETUTCDATE() Function

Example Return the current UTC date and time: SELECT GETUTCDATE(); Definition and Usage The GETUTCDATE() function returns the current database system UTC date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm'…

2 min
Read lesson →
Lesson 290visual

SQL Server ISDATE() Function

Example Check if the expression is a valid date: SELECT ISDATE('2017-08-25'); Definition and Usage The ISDATE() function checks an expression and returns 1 if it is a valid date, otherwise 0. Syntax…

2 min
Read lesson →
Lesson 291visual

SQL Server MONTH() Function

Example Return the month part of a date: SELECT MONTH('2017/08/25') AS Month; Definition and Usage The MONTH() function returns the month part for a specified date (a number from 1 to 12). Syntax MON…

2 min
Read lesson →
Lesson 292visual

SQL Server SYSDATETIME() Function

Example Return the date and time of the SQL Server: SELECT SYSDATETIME() AS SysDateTime; Definition and Usage The SYSDATETIME() function returns the date and time of the computer where the SQL Server…

2 min
Read lesson →
Lesson 293visual

SQL Server YEAR() Function

Example Return the year part of a date: SELECT YEAR('2017/08/25') AS Year; Definition and Usage The YEAR() function returns the year part for a specified date. Syntax YEAR( date ) Parameter Values Pa…

2 min
Read lesson →
Lesson 294visual

SQL Server CAST() Function

SQL Server CAST() Function

2 min
Read lesson →
Lesson 295visual

SQL Server COALESCE() Function

Example Return the first non-null value in a list: SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com'); Definition and Usage The COALESCE() function returns the first non-null val…

2 min
Read lesson →
Lesson 296visual

SQL Server CONVERT() Function

SQL Server CONVERT() Function

2 min
Read lesson →
Lesson 297visual

SQL Server CURRENT_USER Function

Example Return the name of the current user in the SQL Server database: SELECT CURRENT_USER; Definition and Usage The CURRENT_USER function returns the name of the current user in the SQL Server data…

2 min
Read lesson →
Lesson 298visual

SQL Server IIF() Function

Example Return "YES" if the condition is TRUE, or "NO" if the condition is FALSE: SELECT IIF(500<1000, 'YES', 'NO'); Definition and Usage The IIF() function returns a value if a condition is TRUE, or…

2 min
Read lesson →
Lesson 299visual

SQL Server ISNULL() Function

Example Return the specified value IF the expression is NULL, otherwise return the expression: SELECT ISNULL(NULL, 'W3Schools.com'); Definition and Usage The ISNULL() function returns a specified val…

2 min
Read lesson →
Lesson 300visual

SQL Server ISNUMERIC() Function

Example Tests whether the expression is numeric: SELECT ISNUMERIC(4567); Definition and Usage The ISNUMERIC() function tests whether an expression is numeric. This function returns 1 if the expressio…

2 min
Read lesson →
Lesson 301visual

SQL Server NULLIF() Function

Example Compare two expressions: SELECT NULLIF(25, 25); Definition and Usage The NULLIF() function returns NULL if two expressions are equal, otherwise it returns the first expression. Syntax NULLIF(…

2 min
Read lesson →
Lesson 302visual

SQL Server SESSION_USER Function

Example Return the user name of the current user: SELECT SESSION_USER; Definition and Usage The SESSION_USER function returns the name of the current user in the SQL Server database. Syntax SESSION_U…

2 min
Read lesson →
Lesson 303visual

SQL Server SESSIONPROPERTY() Function

Example Return the session settings for a specified option: SELECT SESSIONPROPERTY('ANSI_NULLS'); Definition and Usage The SESSIONPROPERTY() function returns the session settings for a specified opti…

2 min
Read lesson →
Lesson 304visual

SQL Server SYSTEM_USER Function

Example Return the login name information for the current user: SELECT SYSTEM_USER; Definition and Usage The SYSTEM_USER function returns the login name for the current user. Syntax SYSTEM_USER Techn…

2 min
Read lesson →
Lesson 305visual

SQL Server USER_NAME() Function

Example Return the database user name (will return the current user since no id is specified): SELECT USER_NAME(); Definition and Usage The USER_NAME() function returns the database user name based o…

2 min
Read lesson →
Lesson 306visual

MS Access Functions

MS Access has many built-in functions. This reference contains the string, numeric, and date functions in MS Access. MS Access String Functions Function Description Asc Returns the ASCII value for th…

4 min
Read lesson →
Lesson 307visual

MS Access Asc() Function

Example Return the ASCII value of the first character in "CustomerName": SELECT Asc(CustomerName) AS NumCodeOfFirstChar FROM Customers; Definition and Usage The Asc() function returns the ASCII value…

2 min
Read lesson →
Lesson 308visual

MS Access C hr() Function

Example Return the character based on the number code 65: SELECT Chr(65) AS CodeToCharacter; Definition and Usage The Chr() function returns the character for the specified ASCII number code. Syntax…

2 min
Read lesson →
Lesson 309visual

MS Access Concat With &

Example Add 3 columns together into one "Address" column: SELECT Address & ", " & PostalCode & ", " & City AS Address FROM Customers; Definition and Usage The & operator allows you to add two or more…

2 min
Read lesson →
Lesson 310visual

MS Access CurDir() Function

Example CurDir() CurDir("D") Result: C:\Documents and Settings\user\My Documents D:\ Definition and Usage The CurDir() function returns the full path for a specified drive. Syntax CurDir( drive ) Par…

2 min
Read lesson →
Lesson 311visual

MS Access Format() Function

Example Format the "Price" column to Currency: SELECT Format(Price, "Currency") AS FormattedPrice FROM Products; Definition and Usage The Format() function formats a value with the specified format.…

2 min
Read lesson →
Lesson 312visual

MS Access InStr() Function

Example Search for "t" in string "Customer", and return position: SELECT InStr("Customer", "t") AS MatchPosition; Definition and Usage The InStr() function gets the position of the first occurrence o…

2 min
Read lesson →
Lesson 313visual

MS Access InstrRev() Function

Example Search for "t" in string "Customer" (start from the end of the string) and return position: SELECT InstrRev("Customer", "t") AS MatchPosition; Definition and Usage The InstrRev() function get…

2 min
Read lesson →
Lesson 314visual

MS Access LCase() Function

MS Access LCase() Function

2 min
Read lesson →
Lesson 315visual

MS Access Left() Function

Example Extract 3 characters from a string (starting from left): SELECT Left("SQL Tutorial", 3) AS ExtractString; Definition and Usage The Left() function extracts a number of characters from a strin…

2 min
Read lesson →
Lesson 316visual

MS Access Len() Function

Example Return the length of a string: SELECT Len("SQL Tutorial") AS LengthOfString; Definition and Usage The Len() function returns the length of a string. Syntax Len( string/varname ) Parameter Val…

2 min
Read lesson →
Lesson 317visual

MS Access LTrim() Function

Example Remove leading spaces from a string: SELECT LTrim(" SQL Tutorial") AS LeftTrimmedString; Definition and Usage The LTrim() function removes leading spaces from a string. Note: See also the RTr…

2 min
Read lesson →
Lesson 318visual

MS Access Mid() Function

Example Extract characters from a string, starting at position 3: SELECT Mid("SQL Tutorial", 3) AS ExtractString; Definition and Usage The Mid() function extracts some characters from a string (start…

2 min
Read lesson →
Lesson 319visual

MS Access Replace() Function

Example Replace "i" with "a" in the string: SELECT Replace("My name is Willy Wonka", "i", "a") AS ReplaceString; Definition and Usage The Replace() function replaces a substring within a string, with…

2 min
Read lesson →
Lesson 320visual

MS Access Right() Function

Example Extract 4 characters from a string (starting from right): SELECT Right("SQL Tutorial is cool", 4) AS ExtractString; Definition and Usage The Right() function extracts a number of characters f…

2 min
Read lesson →
Lesson 321visual

MS Access RTrim() Function

Example Remove trailing spaces from a string: SELECT RTrim("SQL Tutorial ") AS RightTrimmedString; Definition and Usage The RTrim() function removes trailing spaces from a string. Note: See also the…

2 min
Read lesson →
Lesson 322visual

MS Access Space() Function

Example Return a string with 5 spaces: SELECT Space(5) AS SpaceString; Definition and Usage The Space() function returns a string of the specified number of space characters. Syntax Space( number ) P…

2 min
Read lesson →
Lesson 323visual

MS Access Split() Function

Example Split strings: SELECT Split("SQL Tutorial is fun!") AS SplitString; Result: {"SQL", "Tutorial", "is", "fun!"} SELECT Split ("red:green:yellow:blue", ":", 2) AS SplitString; Result: {"red", "g…

2 min
Read lesson →
Lesson 324visual

MS Access Str() Function

Example Return a number as a string: SELECT Str(42) AS ConvertToString; Definition and Usage The Str() function returns a number as a string. Syntax Str( number ) Parameter Values Parameter Descripti…

2 min
Read lesson →
Lesson 325visual

MS Access StrComp() Function

Example Compare two strings: SELECT StrComp("SQL Tutorial", "SQL Tutorial") AS CompString; Definition and Usage The StrComp() function compares two strings. The result is returned as an integer based…

2 min
Read lesson →
Lesson 326visual

MS Access StrConv() Function

Example Convert a string: SELECT StrConv("SQL Tutorial is cool", 1) AS ConvertedString; Definition and Usage The StrConv() function returns a converted string. Syntax StrConv( string1, conversion, LC…

2 min
Read lesson →
Lesson 327visual

MS Access StrReverse() Function

Example Reverse a string: SELECT StrReverse("SQL Tutorial") AS StringReverse; Definition and Usage The StrReverse() function reverses a string and returns the result. Syntax StrReverse( string ) Para…

2 min
Read lesson →
Lesson 328visual

MS Access Trim() Function

Example Remove leading and trailing spaces from a string: SELECT Trim(" SQL Tutorial ") AS TrimmedString; Definition and Usage The Trim() function removes both leading and trailing spaces from a stri…

2 min
Read lesson →
Lesson 329visual

MS Access UCase() Function

MS Access UCase() Function

2 min
Read lesson →
Lesson 330visual

MS Access Abs() Function

Example Return the absolute value of a number: SELECT Abs(-243.5) AS AbsNum; Definition and Usage The Abs() function returns the absolute (positive) value of a number. Syntax Abs( number ) Parameter…

2 min
Read lesson →
Lesson 331visual

MS Access Atn() Function

Example Return the arc tangent of a number: SELECT Atn(5) AS AtnNum; Definition and Usage The Atn() function returns the arc tangent of a number. Syntax Atn( number ) Parameter Values Parameter Descr…

2 min
Read lesson →
Lesson 332visual

MS Access Avg() Function

Example Return the average value for the "Price" column in the "Products" table: SELECT Avg(Price) AS AveragePrice FROM Products; Definition and Usage The Avg() function returns the average value of…

2 min
Read lesson →
Lesson 333visual

MS Access Cos() Function

Example Return the cosine of an angle: SELECT Cos(5) AS CosNum; Definition and Usage The Cos() function returns the cosine of an angle. Syntax Cos( number ) Parameter Values Parameter Description num…

2 min
Read lesson →
Lesson 334visual

MS Access Count() Function

Example Return the number of products in the "Products" table: SELECT Count(ProductID) AS NumberOfProducts FROM Products; Definition and Usage The Count() function returns the number of records retur…

2 min
Read lesson →
Lesson 335visual

MS Access Exp() Function

Example Return e raised to the 5th power: SELECT Exp(5) AS ExpNum; Definition and Usage The Exp() function returns e raised to the power of a specified number. The constant e (2.718281�), is the ba…

2 min
Read lesson →
Lesson 336visual

MS Access Fix() Function

Example Return the integer part of a number: SELECT Fix(756.43) AS FixNum; Definition and Usage The Fix() function returns the integer part of a number. Syntax Fix( number ) Parameter Values Paramete…

2 min
Read lesson →
Lesson 337visual

MS Access Format() Function

Example Format a numeric expression to percent: SELECT Format(0.5, "Percent") AS FormattedNum; Definition and Usage The Format() function formats a numeric value with the specified format. Syntax For…

2 min
Read lesson →
Lesson 338visual

MS Access Int() Function

Example Return the integer part of a number: SELECT Int(756.43) AS IntNum; Definition and Usage The Int() function returns the integer part of a number. Note: If number is negative, this function ret…

2 min
Read lesson →
Lesson 339visual

MS Access Max() Function

Example Find the price of the most expensive product in the "Products" table: SELECT Max(Price) AS LargestPrice FROM Products; Definition and Usage The Max() function returns the maximum value in a s…

2 min
Read lesson →
Lesson 340visual

MS Access Min() Function

Example Find the price of the cheapest product in the "Products" table: SELECT Min(Price) AS SmallestPrice FROM Products; Definition and Usage The Min() function returns the minimum value in a set of…

2 min
Read lesson →
Lesson 341visual

MS Access Randomize() Function

Definition and Usage The Randomize() function initializes the random number generator (used by Rnd() ) with a seed. Syntax Randomize( seed ) Parameter Values Parameter Description seed Optional. A nu…

2 min
Read lesson →
Lesson 342visual

MS Access Rnd Function

Example Return one random number between 1 and 10, and another random number between 100 and 499: SELECT Int((10 - 1 + 1) * Rnd + 1) AS RandNumBetween1and10, Int((499 - 100 + 1) * Rnd + 100) AS RandN…

2 min
Read lesson →
Lesson 343visual

MS Access Round() Function

Example Round the Price column to 1 decimal in the "Products" table: SELECT ProductName, Price, Round(Price, 1) AS RoundedPrice FROM Products; Definition and Usage The Round() function rounds a numbe…

2 min
Read lesson →
Lesson 344visual

MS Access Sgn() Function

Example Return the sign of a number: SELECT Sgn(243.5) AS SgnNum; Definition and Usage The Sgn() function returns the sign of a number. This function will return one of the following: If number > 0,…

2 min
Read lesson →
Lesson 345visual

MS Access Sqr() Function

Example Return the square root of a number: SELECT Sqr(64) AS SqrNum; Definition and Usage The Sqr() function returns the square root of a number. Syntax Sqr( number ) Parameter Values Parameter Desc…

2 min
Read lesson →
Lesson 346visual

MS Access Sum() Function

Example Return the sum of the "Quantity" field in the "OrderDetails" table: SELECT Sum(Quantity) AS TotalItemsOrdered FROM OrderDetails; Definition and Usage The Sum() function calculates the sum of…

2 min
Read lesson →
Lesson 347visual

MS Access Val() Function

Example Read a string and return the numbers found in the string: SELECT Val(PostalCode) FROM Customers; Definition and Usage The Val() function reads a string and returns the numbers found in the st…

2 min
Read lesson →
Lesson 348visual

MS Access Date() Function

Example Return the current system date: SELECT CustomerName, Date() AS CurrentDate FROM Customers; Definition and Usage The Date() function returns the current system date. Syntax Date() Parameter Va…

2 min
Read lesson →
Lesson 349visual

MS Access DateAdd() Function

Example Add two years to a specified date: SELECT DateAdd("yyyy", 2, #22/11/2017#); Definition and Usage The DateAdd() function adds a time/date interval to a date and then returns the date. Syntax D…

2 min
Read lesson →
Lesson 350visual

MS Access DateDiff() Function

Example Return the difference between two dates, in years: SELECT DateDiff("yyyy", #13/01/1998#, #09/05/2017#); Definition and Usage The DateDiff() function returns the difference between two dates.…

2 min
Read lesson →
Lesson 351visual

MS Access DatePart() Function

Example Return the year part of the specified date: SELECT DatePart("yyyy", #09/05/2017#); Definition and Usage The DatePart() function returns a specified part of a date, as an integer. Syntax DateP…

2 min
Read lesson →
Lesson 352visual

MS Access DateSerial() Function

Example Return a date from it's parts: SELECT DateSerial(2017, 4, 20); Definition and Usage The DateSerial() function returns a date from the specified parts (year, month, and day values). Syntax Dat…

2 min
Read lesson →
Lesson 353visual

MS Access DateValue() Function

Example Return a date based on the given string: SELECT DateValue("May 17, 2017"); Definition and Usage The DateValue() function returns a date based on a string. Note: If the given string does not i…

2 min
Read lesson →
Lesson 354visual

MS Access Day() Function

Example Return the day of the month for the date: SELECT Day(#05/17/2017#); Definition and Usage The Day() function returns the day of the month for a given date. This function returns an integer bet…

2 min
Read lesson →
Lesson 355visual

MS Access Format() Function

Example Format the "BirthDate" column to a long date: SELECT Format(BirthDate, "Long Date") AS FormattedBirthDate FROM Employees; Definition and Usage The Format() function formats a date value with…

2 min
Read lesson →
Lesson 356visual

MS Access Hour() Function

Example Return the hour for a specified time: SELECT Hour(#14:48:23#); Definition and Usage The Hour() function returns the hour part of a time/datetime. This function returns an integer between 0 an…

2 min
Read lesson →
Lesson 357visual

MS Access Minute() Function

Example Return the minute part of a specified time: SELECT Minute(#14:48:23#); Definition and Usage The Minute() function returns the minute part of a time/datetime. This function returns an integer…

2 min
Read lesson →
Lesson 358visual

MS Access Month() Function

Example Return the month part for a specified date: SELECT Month(#05/17/2017#); Definition and Usage The Month() function returns the month part for a given date. This function returns an integer bet…

2 min
Read lesson →
Lesson 359visual

MS Access MonthName() Function

Example Return the name of the month based on a number: SELECT MonthName(3); Definition and Usage The MonthName() function returns the name of the month based on a number. Syntax MonthName( number, a…

2 min
Read lesson →
Lesson 360visual

MS Access Now() Function

Example Return the computer system's current date and time: SELECT CustomerName, Now() AS CurrentDateTime FROM Customers; Definition and Usage The Now() function returns the current date and time bas…

2 min
Read lesson →
Lesson 361visual

MS Access Second() Function

Example Return the seconds part of a specified time: SELECT Second(#14:48:23#); Definition and Usage The Second() function returns the seconds part of a time/datetime. This function returns an intege…

2 min
Read lesson →
Lesson 362visual

MS Access Time() Function

Example Return the current system time: SELECT CustomerName, Time() AS CurrentTime FROM Customers; Definition and Usage The Time() function returns the current system time. Syntax Time() Parameter Va…

2 min
Read lesson →
Lesson 363visual

MS Access TimeSerial() Function

Example Return a time from it's parts: SELECT TimeSerial(15, 9, 20); Definition and Usage The TimeSerial() function returns a time from the specified parts (hour, minute, and second value). Syntax Ti…

2 min
Read lesson →
Lesson 364visual

MS Access TimeValue() Function

Example Return a time based on the given string: SELECT TimeValue("17:15:38"); Definition and Usage The TimeValue() function returns a time based on a string. Syntax TimeValue( string ) Parameter Val…

2 min
Read lesson →
Lesson 365visual

MS Access Weekday() Function

Example Return the weekday number for a date: SELECT Weekday(#05/17/2017#); Definition and Usage The Weekday() function returns the weekday number for a given date. This function returns an integer b…

2 min
Read lesson →
Lesson 366visual

MS Access WeekdayName() Function

Example Return the weekday name based on a number: SELECT WeekdayName(3); Definition and Usage The WeekdayName() function returns the weekday name based on a number. Syntax WeekdayName( number, abbre…

2 min
Read lesson →
Lesson 367visual

MS Access Year() Function

Example Return the year part of a specified date: SELECT Year(#05/17/2017#); Definition and Usage The Year() function returns the year part of a given date. This function returns an integer between 1…

2 min
Read lesson →
Lesson 368visual

MS Access CurrentUser() Function

Example Return the name of the current database user: SELECT CurrentUser(); Definition and Usage The CurrentUser() function returns the name of the current database user. Syntax CurrentUser() Technic…

2 min
Read lesson →
Lesson 369visual

MS Access Environ() Function

Example Return a string that contains the value of an operating system environment variable: SELECT Environ(1); Definition and Usage The Environ() function returns a string that contains the value of…

2 min
Read lesson →
Lesson 370visual

MS Access IsDate() Function

Example Check whether the expression can be converted to a date: SELECT IsDate(Now()); Definition and Usage The IsDate() function checks whether an expression can be converted to a date. This functio…

2 min
Read lesson →
Lesson 371visual

MS Access IsNull() Function

Example Check whether the expression is a Null value: SELECT IsNull(null); Definition and Usage The IsNull() function checks whether an expression contains Null (no data). This function returns a Boo…

2 min
Read lesson →
Lesson 372visual

MS Access IsNumeric() Function

Example Check whether the expression is a valid number: SELECT IsNumeric(1030); Definition and Usage The IsNumeric() function checks whether an expression is a valid number. This function returns a B…

2 min
Read lesson →
Lesson 373visual

SQL Quick Reference from W3Schools

SQL Statement Syntax AND / OR SELECT column_name(s) FROM table_name WHERE condition AND|OR condition ALTER TABLE ALTER TABLE table_name ADD column_name datatype or ALTER TABLE table_name DROP COLUMN…

2 min
Read lesson →