MySQL | Common MySQL Queries
Last Updated :
14 Aug, 2021
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly Facebook, Twitter, and Google depends on MySQL data which are designed and optimized for such purpose. For all these reasons, MySQL server becomes the default choice for web applications.
MySQL server is used for data operations like querying, sorting, filtering, grouping, modifying and joining the tables. Before learning the commonly used queries, let us look into some of the advantages of MySQL.
Advantages of MySQL :
- Fast and high Performance database.
- Easy to use, maintain and administer.
- Easily available and maintain integrity of database.
- Provides scalability, usability and reliability.
- Low cost hardware.
- MySQL can read simple and complex queries and write operations.
- InnoDB is default and widely used storage engine.
- Provides strong indexing support.
- Provides SSL support for secured connections.
- Provides powerful data encryption and accuracy.
- Provides Cross-platform compatibility.
- Provides minimized code repetition.
Queries can be understood as the commands which interacts with database tables to work around with data. Some of the commonly used MySQL queries, operators, and functions are as follows :
1. SHOW DATABASES
This displays information of all the existing databases in the server.
Output:
Note : The databases ‘information_schema’, ‘mysql’ and ‘performance_schema’ are system databases which are used internally by MySQL server. A ‘test’ database is meant for testing purpose which is provided during installation.
2. USE database_name
database_name : name of the database
This sets the database as the current database in the MySQL server.
To display the current database name which is set, use syntax
SELECT DATABASE();
3. DESCRIBE table_name
table_name : name of the table
This describes the columns of the table_name with respect to Field, Type, Null, Key, Default, Extra.
4. SHOW TABLES
This shows all the tables in the selected database as a information.
5. SHOW CREATE TABLE table_name
table_name : name of the table
This shows the complete CREATE TABLE statement used by MySQL for creating the table.
6. SELECT NOW()
MySQL queries mostly starts with SELECT statement.
This query shows the current date and time.
Output :
2019-09-24 07:08:30
7. SELECT 2 + 4;
Output :
6
This executes SELECT statement without any table.
SELECT can be used for executing an expression or evaluating an in-built function.
SELECT can also be used for more than one or many columns.
Example :
SELECT 2+4, CURDATE();
Output :
8. Comments
Comments are of two types. Multi-line comments or single-line or end-of-line comment.
/* These are multi-line comments. */
# This is single-line comment.
-- This is also single-line comment.
9. CREATE DATABASE database_name
database_name : name of the database
This statement creates a new database.
10. DROP DATABASE database_name
database_name : name of the database
This statement deletes the database.
Note : User has to be very careful before deleting a database as it will lose all the crucial information stored in the database.
11. CREATE TABLE table_name(column1, column2, column3..)
table_name : name of the table
column1 : name of first column
column2 : name of second column
column3 : name of third column
When the developer start building an application, he needs to create database tables.
This statement creates a new table with the given columns.
Example :
CREATE TABLE employee(
'id' INTEGER NOT NULL AUTO_INCREMENT,
'name' VARCHAR(30) NOT NULL,
'profile' VARCHAR(40) DEFAULT 'engineer',
PRIMARY KEY ('id')
)ENGINE = InnoDB;
Note : You have ‘id’ column as AUTO_INCREMENT with a primary key constraint which ensures that each id is incremented value, avoiding duplication. Storage engine selected is ‘InnoDB’ allowing foreign key constraint and related transactions.
12. AUTO_INCREMENT
It is used to generate a unique identification field for new row.
13. DROP TABLE table_name
table_name : name of the table
This statement deletes the mentioned table.
14. RENAME TABLE old_table_name TO new_table_name
old_table_name : name of the previous table.
new_table_name : name of the new table.
This statement renames the table to a new name.
15. ALTER TABLE table_name ADD(column1, column2, column3..)
table_name : name of the existing table.
column1 : name of first column.
column2 : name of second column.
column3 : name of third column.
This statement adds columns to the existing table.
16. ALTER TABLE table_name DROP(column1)
table_name : name of the existing table.
column1 : name of first column.
This statement deletes specified columns from the existing table.
17. INSERT INTO table_name (column1, column2, column3 . . ) VALUES(value1, value2, value3 . . )
table_name : name of the existing table.
column1 : name of first column.
column2 : name of second column.
column3 : name of third column.
value1 : value for first column.
value2 : value for second column.
value3 : value for third column.
This statement inserts a new record into a table with specified values.
18. UPDATE table_name SET column1 = value1, column2 = value2, column3 = value3.. WHERE condition
table_name : name of the table.
column1 : name of first column.
column2 : name of second column.
column3 : name of third column.
value1 : value for first column.
value2 : value for second column.
value3 : value for third column.
condition : the condition statement.
This statement update records in the table with the new given values for the columns.
Note : WHERE clause in MySQL queries is used to filter rows for a specific condition.
19. DELETE FROM table_name WHERE condition
table_name : name of the table.
condition : the condition statement.
This statement deletes records from the table.
20. SELECT column1, column2, column3.. FROM table_name WHERE condition
table_name : name of the table.
column1 : name of first column.
column2 : name of second column.
column3 : name of third column.
condition : the condition statement.
This statement executes and gives records from specific columns from the table which matches the condition after WHERE clause.
21. SELECT * FROM table_name
table_name: name of the table.
Instead of specifying one column or many columns, you can use an asterisk (*) which represents all columns of table. This query retrieves all records from the table.
22. COUNT
The COUNT function is used to return total number of records matching a condition from any table.
It is one of the known AGGREGATE function.
Example :
SELECT COUNT(*) from student;
Note: AGGREGATE functions allow you to run calculations on data and provide information by using
a SELECT query.
23. MAX
It is used to get the maximum numeric value of a particular column of table.
Example :
SELECT MAX(marks) FROM student_report;
Note: The MIN and MAX functions work correctly on numeric as well as alphabetic values.
24. MIN
It is used to get the minimum numeric value of a particular column of table.
Example :
SELECT MIN(marks) FROM student_report;
Note : The above given example queries can also be nested with each other depending on the requirement.
Example :
SELECT MIN(marks)
FROM student_report
WHERE marks > ( SELECT MIN(marks) from student_report);
25. LIMIT
It is used to set the limit of number of records in result set.
Example :
SELECT *
FROM student limit 4, 10;
This gives 10 records starting from the 5th record.
26. BETWEEN
It is used to get records from the specified lower limit to upper limit.
This verifies if a value lies within that given range.
Example :
SELECT * FROM employee
WHERE age BETWEEN 25 to 45.
27. DISTINCT
This is used to fetch all distinct records avoiding all duplicate ones.
Example :
SELECT DISTINCT profile
FROM employee;
28. IN clause
This verifies if a row is contained in a set of given values.
It is used instead of using so many OR clause in a query.
Example :
SELECT *
FROM employee
WHERE age IN(40, 50, 55);
29. AND
This condition in MySQL queries are used to filter the result data based on AND conditions.
Example :
SELECT NAME, AGE
FROM student
WHERE marks > 95 AND grade = 7;
30. OR
This condition in MySQL queries are used to filter the result data based on OR conditions.
Example :
SELECT *
FROM student
WHERE address = 'Hyderabad' OR address = 'Bangalore';
31. IS NULL
This keyword is used for boolean comparison or to check if the data value of a column is null.
Example :
SELECT *
FROM employee
WHERE contact_number IS NULL;
32. FOREIGN KEY
It is used for pointing a PRIMARY KEY of another table.
Example :
CREATE TABLE Customers
(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
)
CREATE TABLE Orders
(
order_id INT AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY (id) REFERENCES Customers(id)
);
Note: This is not used in the MYISAM storage engine of MySQL server.
InnoDB storage engines supports foreign key constraints.
33. LIKE
This is used to fetch records matching for specified string pattern.
Example :
SELECT *
FROM employee
WHERE name LIKE 'Sh%';
SELECT *
FROM employee
WHERE name LIKE '%Sh%';
Note: Percentage signs (%) in the query represent zero or more characters.
34. JOINS
Joins are the joining of two or more database tables to fetch data based on a common field.
There are various types of joins with different names in different databases.
Commonly known joins are self join, outer join, inner join and many more.
Regular Join :
It is the join which gets all the records from both the tables which exactly match the given condition.
Example :
SELECT student.name, department.name
FROM student JOIN department ON student.department = department.name
Left Join :
It is the join which gets all the records that match the given condition, and also fetch all the records from
the left table.
Example :
SELECT student.name, department.name
FROM student LEFT JOIN department ON student.deptartment = department.name
Right Join :
It is the join which gets all the records that match the given condition, and also fetch all the records from
the right table.
Example :
SELECT student.name, department.name
FROM student RIGHT JOIN department on student.department = department.name
35. ADD or DROP a column
A new column can be added on a database table, if required later on.
Example :
ALTER TABLE employee ADD COLUMN salary VARCHAR(25);
Similarly, any column can be deleted from a database table.
Example :
ALTER TABLE employee DROP COLUMN salary;
Conclusion :
Running MySQL queries are the most commonly-performed tasks used to get data within the process of database management. There are many database management tools like phpMyAdmin, that helps to perform queries and handle transactions comfortably with visual data results. You have scrolled the most common MySQL queries, which are used in daily coding practices. Developer can customize or enhance the queries with respect to a particular requirement.
Similar Reads
MySQL Tutorial
This MySQL Tutorial is made for both beginners and experienced professionals. Whether you're starting with MYSQL basics or diving into advanced concepts, this free tutorial is the ideal guide to help you learn and understand MYSQL, no matter your skill level. From setting up your database to perform
11 min read
MySQL Basics
What is MySQL?
MySQL is a popular open-source Relational Database Management System (RDBMS) that uses SQL (Structured Query Language) for database operations. While MySQL is a specific database system accessible for free and supports various programming languages. In this article, we will explore the importance of
5 min read
MySQL DATE Data Type
MySQL DATE Data Type stores date values in the format 'YYYY-MM-DD' and has a valid range of values from '1000-01-01' to '9999-12-31'. DATE Data Type in MySQLThe Data data type in MySQL is used to store date values in a column. During later data analysis, it is necessary to perform date-time operatio
2 min read
How to Install MySQL on Windows?
Installing MySQL on your Windows PC is a straightforward process, but it requires ensuring that your system meets specific hardware and software prerequisites. In this article, We will learn about How to Install MySQL on Windows by understanding each step in detail. What is MySQL?MySQL is an open-so
4 min read
How to Install MySQL on Linux?
MySQL is an open-source relational database management system that is based on SQL queries. Here, "My" represents the name of the co-founder Michael Widenius's daughter and "SQL" represents the Structured Query Language. MySQL is used for data operations like querying, filtering, sorting, grouping,
3 min read
How to Install MySQL on macOS?
MySQL is an open-source relational database managing system. It is used for implementing databases. For any website or any other application, a database is required to store data of websites and applications. Using MySQL server of data can be created. The database created by MySQL is well-organized
5 min read
How to Install MySQL on Fedora?
MySQL is one of the oldest and most reliable open-source (Available to all) Relational Database Management Systems. Trusted by Millions of users. SQL is used to communicate with Oracle, SQL-Server & MySQL. In MySQL, all data are arranged in the form of a table. MySQL is one of the best RDBMS bei
4 min read
How to Install SQL Workbench For MySQL on Windows?
MySQL Workbench is a unified visual tool for database architects, developers & Database Administrators. It provides data modeling, SQL development & comprehensive administration tools for server configuration & user administration. It is available for all major operating systems like Win
2 min read
How to Install MySQL WorkBench on Ubuntu?
MySQL Workbench is a powerful and widely-used graphical user interface (GUI) tool developed by Oracle Corporation for managing MySQL databases. It provides a comprehensive set of tools for database administrators, architects, and developers to design, develop, and manage MySQL databases visually. My
3 min read
How to Install SQL Workbench For MySQL on Linux?
MySQL Workbench is a visual database design tool that integrates SQL development, administration, database design, creation, and maintenance into a single integrated development environment for the MySQL database system. It was first released in 2014. It is owned by Oracle Corporation. It supports W
2 min read
Connecting to MySQL Using Command Options
In this article, we will learn to connect the MySQL database with a command line interface using command line options. To connect the MySQL database the community provides a command line tool called mysql which comes up with some command line arguments. To connect the MySQL we need to make sure that
2 min read
Java Database Connectivity with MySQL
In Java, we can connect our Java application with the MySQL database through the Java code. JDBC ( Java Database Connectivity) is one of the standard APIs for database connectivity, using it we can easily run our query, statement, and also fetch data from the database. Prerequisite to understand Jav
3 min read
Connect MySQL database using MySQL-Connector Python
While working with Python we need to work with databases, they may be of different types like MySQL, SQLite, NoSQL, etc. In this article, we will be looking forward to how to connect MySQL databases using MySQL Connector/Python.MySQL Connector module of Python is used to connect MySQL databases with
2 min read
How to make a connection with MySQL server using PHP ?
MySQL is a widely used database management system that may be used to power a wide range of projects. One of its main selling features is its capacity to manage large amounts of data without breaking a sweat. There are two approaches that can be used to connect MySQL and PHP code, which are mentione
3 min read
How to Connect to Mysql Server Using VS Code and Fix errors?
MySQL is a relational database management system based on SQL-Structured Query Language used for accessing and managing records in a database. It can be easily connected with programming languages such as Python, Java, and PHP to serve various purposes that require CRUD ( Create,Read,Update,Delete)
4 min read
How to Connect Node.js Application to MySQL ?
To connect the Node App to the MySQL database we can utilize the mysql package from Node Package Manager. This module provides pre-defined methods to create connections, query execution and perform other database related operations. Approach to Connect Node App to MySQLFirst, initialize the node.js
2 min read
MySQL Managing Databases
MySQL Create Database Statement
The MySQL CREATE DATABASE statement is used to create a new database. It allows you to specify the database name and optional settings, such as character set and collation, ensuring the database is ready for storing and managing data. In this article, we are going to learn how we can create database
4 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
MySQL Drop Database
In Database Management Systems managing databases involves not only creating and modifying the data but also removing the databases when they are no longer needed and freeing the space occupied by them. MySQL offers a feature called DROP DATABASE, allowing users to delete databases. In this article,
3 min read
Python MySQL - Create Database
Python Database API ( Application Program Interface ) is the Database interface for the standard Python. This standard is adhered to by most Python Database interfaces. There are various Database servers supported by Python Database such as MySQL, GadFly, mSQL, PostgreSQL, Microsoft SQL Server 2000,
2 min read
NodeJS MySQL Create Database
Introduction: We are going to see how to create and use mysql database in nodejs. We are going to do this with the help of CREATE DATABASE query. Syntax: Create Database Query: CREATE DATABASE gfg_db; Use Database Query: USE gfg_db Modules: NodeJsExpressJsMySql Setting up environment and Execution:
2 min read
MySQL Managing Tables
MySQL CREATE TABLE
Creating tables in MySQL is a fundamental task for organizing and managing data within a database. Tables act as structured containers, similar to spreadsheets, where data is stored in rows and columns. In this article, we will explore the process of creating tables in MySQL using both the Command L
4 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
MySQL RENAME TABLE Statement
The MySQL RENAME TABLE statement is a simple yet powerful command that allows you to change the name of an existing table in your database. This can be useful for various reasons, such as updating table names to better reflect their content or restructuring your database without losing any data. By
5 min read
Drop Multiple Tables in MySQL
DROP statement in a relational database management system (RDBMS) is used to delete a database object such as a table, index, or view. It can be used to delete the complete database also. The general syntax of the DROP command is as follows: Syntax: DROP object object_name; Example: DROP DATABASE db
3 min read
MySQL Temporary Table
Do you want to store the intermediate results of your query in some table but only for a given DB session and not persist for the lifetime? Is there some way to hold temporary data for a short time without making it permanent on the database forever? If you have ever thought about this and wondered
5 min read
Drop Multiple Tables in MySQL
DROP statement in a relational database management system (RDBMS) is used to delete a database object such as a table, index, or view. It can be used to delete the complete database also. The general syntax of the DROP command is as follows: Syntax: DROP object object_name; Example: DROP DATABASE db
3 min read
Drop Multiple Tables in MySQL
DROP statement in a relational database management system (RDBMS) is used to delete a database object such as a table, index, or view. It can be used to delete the complete database also. The general syntax of the DROP command is as follows: Syntax: DROP object object_name; Example: DROP DATABASE db
3 min read
Drop Multiple Tables in MySQL
DROP statement in a relational database management system (RDBMS) is used to delete a database object such as a table, index, or view. It can be used to delete the complete database also. The general syntax of the DROP command is as follows: Syntax: DROP object object_name; Example: DROP DATABASE db
3 min read
Node.js MySQL Drop Table
DROP TABLE Query is used to Delete or Drop a table from MySQL Database. Syntax: This will delete users table. But this will throw error if users table is not there. DROP TABLE users This will delete users table only if it exist. DROP TABLE IF EXISTS users Modules: mysql: To handle MySQL connection a
2 min read
Inserting data into a new column of an already existing table in MySQL using Python
Prerequisite: Python: MySQL Create Table In this article, we are going to see how to Inserting data into a new column of an already existing table in MySQL using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a
2 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
Python: MySQL Create Table
MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases. SQL commands are case insensitive i.e CREATE and create signify
3 min read
Python: MySQL Create Table
MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases. SQL commands are case insensitive i.e CREATE and create signify
3 min read
PHP | MySQL ( Creating Table )
What is a table? In relational databases, and flat file databases, a table is a set of data elements using a model of vertical columns and horizontal rows, the cell being the unit where a row and column intersect. A table has a specified number of columns, but can have any number of rows. Creating a
3 min read
Node.js MySQL Create Table
Introduction: Learn to create a table in MySQL database using NodeJS. We will see how to use the Create Table command in NodeJS using the MySQL module. Prerequisite: Introduction to NodeJS MySQL Setting up environment and Execution: Step 1: Create a NodeJS Project and initialize it using the followi
2 min read
Create Table From CSV in MySQL
CSV (Comma Separated Value) files are a type of file containing data frames that are separated by a comma (generally). These files are textual in format and aren't confined to a specific program or standard, due to which they are widely used. It is quite common for data frames to be stored in form o
3 min read
Node.js MySQL Drop Table
DROP TABLE Query is used to Delete or Drop a table from MySQL Database. Syntax: This will delete users table. But this will throw error if users table is not there. DROP TABLE users This will delete users table only if it exist. DROP TABLE IF EXISTS users Modules: mysql: To handle MySQL connection a
2 min read
Python MySQL - Drop Table
A connector is employed when we have to use MySQL with other programming languages. The work of MySQL-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server. Drop Table Command Drop command affect
2 min read
How to Rename a MySQL Table in Python?
MySQL Connector-Python module is an API in python used to communicate with a MySQL database server. It only requires the standard Python libraries and has no additional dependencies. There are various other modules in Python like PyMySQL and mysqlclient which can be used to access a database server.
3 min read
MySQL Query
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
Nested Select Statement in MySQL
The relational databases, the ability to retrieve and manipulate data with precision is a cornerstone of effective database management. MySQL, a popular relational database management system, provides a powerful tool called the Nested SELECT statement that empowers developers to perform complex and
5 min read
MySQL DISTINCT Clause
When working with databases, you often need to filter out duplicate records to get a clear and accurate result set. MySQL offers a straightforward solution for this with the DISTINCT clause. This clause helps you retrieve only unique rows from your query results, making it an essential tool for data
4 min read
INSERT() function in MySQL
INSERT() : This function in MySQL is used for inserting a string within a string, removing a number of characters from the original string. Syntax : INSERT(str, pos, len, newstr) Parameters : This method accepts four parameter. str - Original string in which we want to insert another string. pos - T
2 min read
MySQL Derived Table
Structured Query Language (SQL) is a powerful tool for managing and querying relational databases, and MySQL is one of the most widely used database management systems. In MySQL, derived tables offer a flexible and efficient way to manipulate and analyze data within a query. In this article, we will
5 min read
MySQL Insert Multiple Rows
MySQL is an open-source Relational Database Management System that stores data in rows and columns. MySQL is designed to be platform-independent, which means it can run on various operating systems, including Windows, Linux, macOS, and more. MySQL is scalable and can handle databases of varying size
5 min read
MySQL INSERT INTO SELECT Statement
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. It stores data in a table format. It provides various statements to perform Create, Read, Update, and Delete operations on a database table. INSERT INTO SELECT statement i
5 min read
MySQL INSERT ON DUPLICATE KEY UPDATE Statement
MySQL INSERT ON DUPLICATE KEY UPDATE statement is an extension to the INSERT statement, that if the row being inserted already exists in the table, it will perform a UPDATE operation instead. INSERT ON DUPLICATE KEY UPDATE in MySQLINSERT ON DUPLICATE KEY UPDATE statement in MySQL is used to handle d
3 min read
MySQL Insert Date Time
In today's world, working with data is now a data-to-data activity, so therefore managing data with proper data and time is also crucial. MySQL provides functionalities to handle data and time properly in the database. Understanding how to insert data and time into MySQL database with functions prov
4 min read
MySQL Insert Date Time
In today's world, working with data is now a data-to-data activity, so therefore managing data with proper data and time is also crucial. MySQL provides functionalities to handle data and time properly in the database. Understanding how to insert data and time into MySQL database with functions prov
4 min read
MySQL UPDATE Statement
MySQL is a popular relational database management system used in applications ranging from small projects to large enterprises. The UPDATE statement in MySQL is essential for modifying existing data in a table. It's commonly used to correct errors, update values, and make other necessary changes. Th
5 min read
MySQL DELETE Statement
In DBMS, CRUD operations (Create, Read, Update, Delete) are essential for effective data management. The Delete operation is crucial for removing data from a database. This guide covers the MySQL DELETE statement, exploring its syntax and providing examples. Understanding how DELETE works helps ensu
6 min read
How to Delete Duplicate Rows in MySQL?
Duplicate rows are a common problem in MySQL databases. Duplicate rows can cause problems with data accuracy and integrity. They can also make it difficult to query and analyze data. They can occur for a variety of reasons, such as: Data entry errorsData import/export errorsDatabase synchronization
3 min read
MySQL DELETE JOIN
MySQL is an open-source, user-friendly, powerful, and popular choice, relational database management system. When maintaining and modifying data, tables usually interact in a complex way. MySQL's DELETE JOIN function is one of its most powerful functions. MySQL DELETE JOIN is explored in detail in t
4 min read
MySQL - ON DELETE CASCADE Constraint
ON DELETE CASCADE constraint is used in MySQL to delete the rows from the child table automatically, when the rows from the parent table are deleted. For example when a student registers in an online learning platform, then all the details of the student are recorded with their unique number/id. All
3 min read
Truncate All Tables in MySQL
TRUNCATE statement is a Data Definition Language (DDL) operation that is used to mark the extent of a table for deallocation (empty for reuse). The result of this operation quickly removes all data from a table, typically bypassing a number of integrity-enforcing mechanisms. In SQL, truncate is used
2 min read
PHP | Inserting into MySQL database
Inserting data into a MySQL database using PHP is a crucial operation for many web applications. This process allows developers to dynamically manage and store data, whether it be user inputs, content management, or other data-driven tasks. In this article, We will learn about How to Inserting into
6 min read
Python MySQL - Update Query
A connector is employed when we have to use MySQL with other programming languages. The work of MySQL-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server. Update Clause The update is used to ch
2 min read
PHP | MySQL UPDATE Query
The MySQL UPDATE query is used to update existing records in a table in a MySQL database. It can be used to update one or more field at the same time. It can be used to specify any condition using the WHERE clause. Syntax : The basic syntax of the Update Query is - Implementation of Where Update Que
2 min read
Node.js MySQL Update Statement
Node.js is an open-source platform for executing JavaScript code on the server-side. It can be downloaded from here. MySQL is an open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). It is the most popular language for adding, accessing, and managing co
2 min read
MySQL Clauses
MySQL WHERE Clause
The MySQL WHERE clause is essential for filtering data based on specified conditions and returning it in the result set. It is commonly used in SELECT, INSERT, UPDATE, and DELETE statements to work on specific data. This clause follows the FROM clause in a SELECT statement and precedes any ORDER BY
5 min read
MySQL ORDER BY Clause
In MySQL, the ORDER BY Clause is used to sort the result set either in ascending order or descending order. By default, the ORDER BY sorts the displayed data in ascending order. If you want your data displayed in descending order we need to use the DESC keyword along with the ORDER BY Clause. To mak
5 min read
MySQL | PARTITION BY Clause
A PARTITION BY clause is used to partition rows of table into groups. It is useful when we have to perform a calculation on individual rows of a group using other rows of that group. It is always used inside OVER() clause. The partition formed by partition clause are also known as Window. This claus
2 min read
Queries using AND ,OR ,NOT operators in MySQL
AND, OR, NOT operators are basically used with WHERE clause in order to retrieve data from table by filtering with some conditions using AND, OR, NOT in MySQL.Here in this article let us see different queries on the student table using AND, OR, NOT operators step-by-step. Step-1:Creating a database
2 min read
Queries using AND ,OR ,NOT operators in MySQL
AND, OR, NOT operators are basically used with WHERE clause in order to retrieve data from table by filtering with some conditions using AND, OR, NOT in MySQL.Here in this article let us see different queries on the student table using AND, OR, NOT operators step-by-step. Step-1:Creating a database
2 min read
MySQL EXISTS Operator
The EXISTS operator in MySQL is a powerful boolean operator used to test the existence of any record in a subquery. It returns true if the subquery yields one or more records, enabling efficient data retrieval and manipulation, particularly in large datasets. The operator is often paired with subque
6 min read
MySQL Aggregate Functions
MySQL Data Constraints
MySQL NOT NULL Constraint
In the database management system maintaining data reliability and data accuracy is very important. MySQL is a popular relational database management system, which offers various constraints to provide security and ensure the integrity of the stored data. There are various key constraints present in
4 min read
MySQL UNIQUE Constraint
A UNIQUE constraint in MySQL ensures that all values in a column or a set of columns are distinct from one another. This constraint is used to prevent duplicate entries in a column or combination of columns, maintaining data integrity. UNIQUE Constraint in MySQLA UNIQUE constraint in MySQL prevents
4 min read
MySQL Primary Key
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. It stores data in a table format and to uniquely identify each record in a table, we require a Primary Key. In this article, we will learn how to add, modify, and remove t
4 min read
MySQL FOREIGN KEY Constraint
A FOREIGN KEY is a field/column(or collection of fields) in a table that refers to a PRIMARY KEY in another table. It is used for linking one or more than one table together. FOREIGN KEY is also called referencing key. A Foreign key creates a link (relation) between two tables thus creating referent
7 min read
MySQL COMPOSITE KEY
In MySQL, a composite key is a combination of two or more columns in a table that uniquely identifies each entry. It is a candidate key made up of many columns. MySQL guarantees column uniqueness only when they are concatenated. If they are extracted separately, the uniqueness cannot be maintained.
4 min read
MySQL UNIQUE Constraint
A UNIQUE constraint in MySQL ensures that all values in a column or a set of columns are distinct from one another. This constraint is used to prevent duplicate entries in a column or combination of columns, maintaining data integrity. UNIQUE Constraint in MySQLA UNIQUE constraint in MySQL prevents
4 min read
MySQL DEFAULT Constraint
The MySQL DEFAULT constraint returns the default value for a table column. The DEFAULT value of a column is a value used in the case, when there is no value specified by the user. To use this function there should be a DEFAULT value assigned to the column. Otherwise, it will generate an error. Synta
3 min read
MySQL Joining Data
MySQL Inner Join
In MySQL, the INNER JOIN clause is used to combine rows from two or more tables based on a related column between them. The INNER JOIN returns rows when there is at least one match in both tables. If there are rows in the left table that do not have matches in the right table, those rows will not be
7 min read
MySQL LEFT JOIN
In databases, data is often stored in multiple tables, making it necessary to combine them to fetch required information. MySQL JOIN statements enable merging tables based on common columns. In this article, we'll explore the MySQL LEFT JOIN keyword, a type of outer join that returns all records fro
5 min read
MySQL RIGHT JOIN
In databases, data is stored in multiple tables and it is often necessary sometimes to combine two or more tables to fetch the required data. In MySQL, joins enable the merging of multiple tables based on the common columns. In this article, we are going to explore MySQL RIGHT JOINS which is a type
5 min read
MySQL SELF JOIN
Joins are very important for effective data retrieval and analysis. The 'JOIN' clause is used to combine data from two or more tables using the common column between them. In MySql, there are many types of joins like INNER JOIN, OUTER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, and SELF JOIN. In this ar
5 min read
MySQL CROSS JOIN
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. It stores data in a table format. It provides various statements to perform Create, Read, Update, and Delete operations on a database table. Among these operations, MySQL
5 min read
MySQL UPDATE JOIN
A widely used open-source relational database management system that allows you to efficiently store, organize, and retrieve data. Developed by Oracle, My SQL is widely used for building and managing databases that handle interactive websites and applications. We'll discuss the syntax, and demonstra
6 min read
MySQL DELETE JOIN
MySQL is an open-source, user-friendly, powerful, and popular choice, relational database management system. When maintaining and modifying data, tables usually interact in a complex way. MySQL's DELETE JOIN function is one of its most powerful functions. MySQL DELETE JOIN is explored in detail in t
4 min read
MySQL | Recursive CTE (Common Table Expressions)
What is a CTE? In MySQL every query generates a temporary result or relation. In order to give a name to those temporary result set, CTE is used. A CTE is defined using WITH clause. Using WITH clause we can define more than one CTEs in a single statement. A CTE can be referenced in the other CTEs th
5 min read
MySQL Functions
DATE() in MySQL
The DATE() function in MySQL is designed to extract the date portion (year, month, and day) from a given date, datetime or timestamp value. In this article, We will learn about DATE() in MySQL by understanding their examples. DATE() in MySQLIn MySQL the DATE() function is used to extract the date pa
2 min read
TRUNCATE() Function in MySQL
The TRUNCATE() function in MySQL is a valuable tool for manipulating numerical values by removing their decimal parts without rounding. It allows us to limit the precision of numbers to a specified number of decimal places or even truncate them to the nearest integer. In this article, We will learn
6 min read
Mathematical functions in MySQL
Mathematical functions in MySQL are essential tools for performing a variety of numerical operations directly within SQL queries. These built-in functions enable users to execute calculations, manipulate numeric data, and perform statistical analysis efficiently. In this article, We will learn about
3 min read
MySQL | CONVERT( ) Function
The MySQL CONVERT() function is used for converting a value from one datatype to a different datatype. The MySQL CONVERT() function is also used for converting a value from one character set to another character set. It accepts two parameters which are the input value and the type to be converted in
2 min read
LTRIM() Function in MySQL
LTRIM() : This function in MySQL is used to remove leading spaces from a string. Syntax : LTRIM(str) Parameter : It accepts one parameter as mentioned above and described below as follows. str – The string from which we want to remove leading spaces. Returns : It returns a string after truncating al
2 min read
UCASE() or UPPER() Function in MySQL
1. UCASE() : This function could be used to convert a string to upper-case. This function is similar to the UPPER() function. UPPER()\UCASE() are built-in MySQL function. Syntax : SELECT UCASE(text) Example - SELECT UCASE("MySQL on geeksforgeeks is FUN!") AS UpperText; Output : UpperTextMYSQL ON GEE
1 min read
RTRIM() Function in MySQL
RTRIM() : It is the function in MySQL that is used to remove trailing spaces from a string. Syntax : RTRIM(str) Parameter : RTRIM() function accepts one parameter as mentioned above and described below. str –The string from which we want to remove trailing spaces. Returns : It returns a string after
3 min read
MySQL ISNULL( ) Function
The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL; otherwise, it returns 0. The ISNULL() function in MySQL accepts the expression as a parameter and returns an integer with a value of a value 0 or 1 dependi
2 min read
IFNULL in MySQL
In MySQL, the IFNULL() function is a powerful tool used to handle NULL values by providing an alternative value when a specified expression evaluates to NULL. This function helps ensure that queries return meaningful or default values instead of NULL which can be particularly useful in data analysis
4 min read
MySQL CASE() Function
MySQL CASE function is a conditional statement that returns a value when the first condition is met. Once a condition is met, the CASE function does not check for other conditions. If no condition is met it returns the output in ELSE part. CASE Function in MySQLThe CASE Function in MySQL allows usin
4 min read
MySQL | CAST( ) Function
The MySQL CAST() function is used for converting a value from one datatype to another specific datatype. The CAST() function accepts two parameters which are the value to be converted and the datatype to which the value needs to be converted. The datatypes in which a given value can be converted are
3 min read
MYSQL View
MySQL is an open-source RDBMS, i.e. Relational Database Management System which is maintained by Oracle. MySQL has support for major operating systems like Windows, MacOS, Linux, etc. MySQL makes it easy for users to interact with your relational databases, which store data in the form of tables. Yo
11 min read
Different types of MySQL Triggers (with examples)
A MySQL trigger is a stored program (with queries) which is executed automatically to respond to a specific event such as insertion, updation or deletion occurring in a table. There are 6 different types of triggers in MySQL: 1. Before Update Trigger: As the name implies, it is a trigger which enact
6 min read
MySQL Miscellaneous Topics
Different types of Procedures in MySQL
A procedure is a subroutine (like a subprogram) in a regular scripting language, stored in a database. In the case of MySQL, procedures are written in MySQL and stored in the MySQL database/server. A MySQL procedure has a name, a parameter list, and SQL statement(s). There are four different types o
5 min read
MySQL Vulnerabilities
We are living in a digital era, as the internet and technology are expanding and becoming more and more popular with each passing day, so are the crimes committed on it. In recent years, the cyber-crimes on businesses or in general have significantly grown. These malicious cybercriminals take advant
6 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly
9 min read
MySQL Interview Questions
MySQL is a Free open-source Relational Database Management System(RDMS) that stores data in a structured tabular format using rows and columns. It uses Structured Query Language (SQL) for accessing, managing, and manipulating databases. It was originally developed by MySQL AB, a Swedish company, and
13 min read