Here is the list of all important MySQL functions. Each function has been explained along with suitable example.
*
MySQL Group By Clause - The MySQL GROUP BY statement is used along with the SQL aggregate functions like SUM to provide means of grouping the result dataset by certain database table column(s).
*
MySQL IN Clause - This is a clause which can be used alongwith any MySQL query to specify a condition.
*
MySQL BETWEEN Clause - This is a clause which can be used alongwith any MySQL query to specify a condition.
*
MySQL UNION Keyword - Use a UNION operation to combine multiple result sets into one.
*
MySQL COUNT Function - The MySQL COUNT aggregate function is used to count the number of rows in a database table.
*
MySQL MAX Function - The MySQL MAX aggregate function allows us to select the highest (maximum) value for a certain column.
*
MySQL MIN Function - The MySQL MIN aggregate function allows us to select the lowest (minimum) value for a certain column.
*
MySQL AVG Function - The MySQL AVG aggregate function selects the average value for certain table column.
*
MySQL SUM Function - The MySQL SUM aggregate function allows selecting the total for a numeric column.
*
MySQL SQRT Functions - This is used to generate a square root of a given number.
*
MySQL RAND Function - This is used to generate a random number using MySQL command.
*
MySQL CONCAT Function - This is used to concatenate any string inside any MySQL command.
*
MySQL DATE and Time Functions - Complete list of MySQL Date and Time related functions.
*
MySQL Numeric Functions - Complete list of MySQL functions required to manipulate numbers in MySQL.
*
MySQL String Functions - Complete list of MySQL functions required to manipulate strings in MySQL.
2. CREATE DATABASE CREATE DATABASE creates a database with the given name. Syntax CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name Example CREATE schema test1; CREATE database test1;
3. CREATE TABLE creates a table with the given name. You must have the CREATE privilege for the table. Syntax CREATE TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [table_options] Example CREATE TABLE `test`.`students` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `name` VARCHAR( 30 ) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = InnoDB
4. CREATE INDEX creates a index with the given name. Syntax CREATE INDEX index_name ON tbl_name (index_col_name,...) Example create index tt on students(name)
5. CREATE VIEW The CREATE VIEW statement creates a new view, or replaces an existing one if the OR REPLACE clause is given. Syntax CREATE [OR REPLACE] VIEW view_name [(column_list)] AS select_statement Example CREATE VIEW test.v AS SELECT * FROM t;
6. DROP DATABASE DROP DATABASE drops all tables in the database and deletes the database. Be very careful with this statement! Syntax DROP {DATABASE | SCHEMA} [IF EXISTS] db_name Example Drop database test;
7. DROP index indexname DROP INDEX drops the index named index_name from the table DROP INDEX index_name ON tbl_name DROP TABLE removes one or more tables. DROP TABLE [IF EXISTS] tbl_name [, tbl_name] ...
8. RENAME TABLE RENAME TABLE current_db.tbl_name TO other_db.tbl_name; ALTER TABLE You can rename a column using a CHANGE old_col_name new_col_name column_definition clause. ALTER TABLE t1 CHANGE a b INTEGER; ALTER TABLE `t` ENGINE = MYISAM
9.
10. Syntax INSERT INTO table_name VALUES (value1, value2, value3,...) INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) Example INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger') The INSERT INTO statement is used to insert a new row in a table. INSERT
11.
12.
13. The SELECT statement is used to select data from a database. The result is stored in a result table, called the result-set. SELECT column_name(s) FROM table_name [WHERE where_condition] SELECT Syntax SELECT LastName,FirstName FROM Persons Example
14. Delete the records inside the table. TRUNCATE TRUNCATE TABLE table_name Syntax TRUNCATE TABLE Persons Example
15.
16.
17. Example HELP ‘select' The HELP statement returns online information from the MySQL Reference manual. HELP ' search_string ' USE db_name The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued: HELP Syntax
18.
19.
20.
21.
22.
23. INNER JOIN Author Table Author_ID First_Name Last_name 1 Chad Russell 2 Jon Stephens 3 Mike Hillyer Book_Author ISBN Author_ID 1590593324 1 1590593324 2
24. An INNER JOIN query returns one row for each pair or matching rows in the tables being joined. Take our Author and Book_Author tables as an example: SELECT First_Name, Last_Name, ISBN FROM Author INNER JOIN Book_Author ON Author.Author_ID = Book_Author.Author_ID; First_Name Last_Name ISBN Chad Russell 1590593324 Jon Stephens 1590593324
25. OUTER JOIN The third author in the Author table is missing because there are no corresponding rows in the Book_Author table. When we need at least one row in the result set for every row in a given table, regardless of matching rows, we use an OUTER JOIN query. There are three variations of the OUTER JOIN syntax: LEFT OUTER JOIN, RIGHT OUTER JOIN.. The syntax used determines which table will be fully represented. A LEFT OUTER JOIN returns one row for each row in the table specified on the left side of the LEFT OUTER JOIN clause. The opposite is true for the RIGHT OUTER JOIN clause.
26. In each case, a row of NULL values is substituted when a matching row is not present. The following is an example of a LEFT OUTER JOIN: SELECT First_Name, Last_Name, ISBNFROM Author LEFT OUTER JOIN Book_Author ON Author.Author_ID = Book_Author.Author_ID; First_Name Last_Name ISBN Chad Russell 1590593324 Jon Stephens 1590593324 Mike Hillyer NULL The third author is returned in this example, with a NULL value for the ISBN column, indicating that there are no matching rows in the Book_Author table.