A transaction is used to check whether all SQL statements get executed successfully or not. A Single transaction starts with a particular statement and ends after the completion of all the SQL statements executed successfully. If all SQL statemen...

Concurrency Control
when multiple users accessing a same database at the same time, If any change made by any one of the user do not adversely affect work of the other users.
Locking technique in concurrency control means use a lock variable wi...

Hello Readers, If you are using CodeIgniter you want to fetch limited MySQL results then in this blog we will learn how to to this.
Suppose you want only first 200 chars of a field then you should only fetch limited results, this wil...

Retrieve last message between multiple users and display it in inbox
Hello friends today I am going to tell you how to display last conversation in Inbox. For example: In whatsapp chat list we can see the last conversation of each us...

Hello friends, This tutorial will help you to insert excel sheet data into the MySQL database using PHP I have also included the snapshots which will help you to understand more clearly.
Import Students: You can import students by cl...

MySQl IN operator facilitates us to match a column's value against multiple values in one go.
As most of us are aware that we use WHERE clause for giving any condition in SELECT, INSERT, UPDATE, DELETE statements, so whenever we ...

Hello friends, I was working on the project where I need to import countries database with their country codes. I am providing you the countries database with the help of which you can display list for countries with their country codes on your w...

Hello friends, I was facing issue in database. I wanted the auto increment should start from 1.
There were 20 rows in table. When I deleted all the rows from the table and inserted new row then auto increment started from id = 21 instead of 1....

Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to use SQL Min () Function in Sql.
SQL Min () Function is used for getting the minimum value from the selected field.
Syntax of SQL Min ():
se...

CONCAT function is mysql plays a vital role. The CONCAT() function combine or concatenate the list of strings together .
We have 2 types of concat function ->
CONCAT() – This function will concate list of string together without...

The IFNULL( ) function is available in MySQL, and not in SQL Server or Oracle. This function takes two arguments.
If the first argument is not NULL, the function returns the first argument. Otherwise, the second argument is...

How to Install MySQL on Ubuntu:
Step 1 - Installing MySQL
To install MySQL you need to update the package index on your server and then install the package with apt-get.
Write the following commands to install MySQL
$ sudo apt-get u...

Inserting data to a database would be possible by using SQL statements, specifically the INSERT command. Data can be entered into the database using insert query into the function, here is simple line of code that will create a database usi...

Left Join:
Left Join is used to join two tables and it return all rows from table 1 and matching rows from table 2. The result is NULL for unmatched rows for table 2. Left Join keyword is used to apply Left Join on two tables.
Syntax for Le...

TRUNCATE TABLE Statement:
TRUNCATE Statement is used to remove all records from a table. It is a Data Definition Language (DDL) Statement as it deletes all records and only structure remains. It is similar to delete statement but without where...

Null Values:
Null values denotes missing data in a table or a database. If a column does not have any NOT NULL constraint then for that column there can be NULL values. By default a column can have NULL values.
We cannot use comparison oper...

Combining Results of two or SELECT Statements using UNION OPERATOR:
UNION Operator is used to combine the results of two or more SELECT statements. But UNION operator does not return duplicate rows so to return duplicate rows UNION ALL operato...

Sub Queries:
Sub Queries are those query which comes within another query and are written after the WHERE clause.They are also known as Inner query or nested query.
It is used to return records that are used in the main query as a conditio...

DELETE Statement:
It is used to delete existing records from a table. It can delete all records from a table if where condition is not given and if where condition is given than it will delete selected records which will meet the condition.
...

Group By :
It is used to group the result-set by one or more column. It is used in conjunction with aggregate functions provided by Structured Query Language . If order by is used then Group By must come before Order By clause.
Syntax1:
...

Sometimes we need to find table list present in a database so that we can identify which table we have to create and which one not.
To work in a particular database we need to use the below statement first:
use database_name;
Example:
...

Sometimes we need to check the CREATE TABLE syntax for already created table in the database. When we need to check what kind of columns and what datatype a column has in a table then we require the CREATE TABLE syntax for that table.
Syntax
...

To create a table in MySQL, we use the CREATE TABLE statement. A table is a combination of row and columns.
CREATE TABLE Syntax
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
....
);
In the a...

Sometimes we need to filter records based on some conditions, for that we use the AND & OR operators in MySQL.
AND operator - We use AND operator if we require both conditions in a query means the AND operator displays a record only if bot...

In MySQL, the LIMIT Clause is used to return the specified number of records means by using LIMIT we can specify how many records we want to return from a table..
The LIMIT Clause is useful when, we want to select some records from a table whi...

Sometimes we need to find the last inserted record into table. We can do this by using ORDER by and LIMIT.
Syntax:
SELECT *
FROM table_name
ORDER by id DESC
LIMIT 1;
Example: Suppose we have a table named "tickit" and we want to fi...

In MySQL, aliases are used to give temporarily name to a table or a column. When we write a query we use Aliases to make column name more readable.
Alias Syntax for Columns
SELECT column_name AS alias_name
FROM table_name;
Alias Synta...

In MySQL, the LIKE operator is used to search for a specified pattern for a column in a WHERE clause .
LIKE Syntax
SELECT column_name
FROM table_name
WHERE column_name LIKE pattern;
We have a table "employee" as below:
employe...

In MySQL, the UPDATE statement is used to update existing records in a table.
UPDATE Syntax
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
In the above syntax, WHERE clause specifies which row o...

In MySQL, the IN operator is used to allow us specify multiple values in a WHERE clause.
IN Operator Syntax
SELECT column_name
FROM table_name
WHERE column_name IN (value1,value2,...);
We have a table "employee" as below:
empl...

In MySQL, the BETWEEN operator is used to select values (values can be numbers, text, or dates) from a column within a specified range.
BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
...

In MySQL, the ORDER by keyword is used to get records from a table in sorted order. The ORDER BY keyword can use one or more columns to sort the result-set.
We can sort the records in both ascending and descending order.By default, ORDER by ke...

In MySQL, the WHERE clause is used to filter records from a table. The WHERE clause is used to get the records that match the specified criteria in that.
WHERE Clause Syntax
SELECT column_name,column_name
FROM table_name
WHERE column_name...

In MySQL, The SELECT statement is used to select data from a table.
SELECT Syntax
SELECT column_name,column_name
FROM table_name;
and to select all records
SELECT * FROM table_name;
We have a table "employee" as below:
...

The GROUP by statement is used with the aggregate functions to group the result by one or more columns.
GROUP by Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP by column_...

The HAVING clause is used with aggregate functions as the WHERE clause can not be used with them.
HAVING Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HA...

In SQL, FORMAT() function is used to format a column value means how a field will to be displayed.
FORMAT() Syntax
SELECT FORMAT(column_name,format) FROM table_name;
In the above syntax parameters are as below:
Parameter Descri...

In SQL, NOW() function is used to return the current system date and time.
NOW() Syntax
SELECT NOW() FROM table_name;
We have a table "employee" as below:
employee
id first_name last_name salary
........

In MySQL, LEN() function is used to return the length of the value in a column (text field) in a table.
LEN() Syntax
SELECT LEN(column_name) FROM table_name;
We have a table "employee" as below:
employee
id first_name ...

In MySQL, SUM() function is used to return the total sum of a numeric column in a table.
SUM() Syntax
SELECT SUM(column_name) FROM table_name;
We have a table "employee" as below:
employee
id first_name last_nam...

TRUNCATE
TRUNCATE comes under DDL(Data Definition Language).
TRUNCATE removes only rows from the table but the structure of the table remains same.
Data can not be roll backed if we use "TRUNCATE" command to delete data.
Can not use WHERE...

In MySQL, the DEFAULT constraint is used to insert value into a column in a table. If there is no value is specified for a column then the default value will be added to column for all new records.
DEFAULT Constraint on CREATE TABLE
The fol...

In MySQL, the CHECK constraint is used to put limit on value range on value inside a column.
CHECK Constraint on CREATE TABLE
The following statement creates a CHECK constraint on the "id" column when the "employee" table is created. The CH...

Note that the "P_Id" column in the "Orders" table points to the "P_Id" column in the "Persons" table.
In MySQL, the FOREIGN KEY on one table is used to point a PRIMARY KEY in another table.
We have two tables with the following values.
...

In MySQL, the PRIMARY KEY constraint is used to uniquely identify each record in a table.
Primary key contains UNIQUE values only and the column defined as Primary key column can not be NULL. A table can have only one PRIMARY KEY.
PRIMARY K...

<-- Chapter 25: SQL Join
Chapter 26
SQL Inner Join
SQL Inner Join clause is used to fetch all the rows from more than two tables in which there is a match between the columns. Inner Join is similar like Join clause.
Lets see an ...

In MySQL, the UNIQUE constraint is used to uniquely identify each record in a table.
UNIQUE Constraint on CREATE TABLE
The following statement creates a UNIQUE constraint on the "id" column when the "employee" table is created:
Example
...