MySQL INSERT INTO, UPDATE, DELETE Query Examples

MySQL INSERT INTO, UPDATE, DELETE Query Examples

In MySQL Tutorial Point; You will learn how to use MySQL statements like SELECT, INSERT INTO, UPDATE, DELETE with examples.

Here, We will describe about the MySQL most used statement. we would love to share with you how insert or delete/remove single or multiple rows into MySQL database table, how to select or update data into MySQL database table.

  • The most commonly used statement of MySQL Select statement. MySQL SELECT statement used to fetch data/records from database table.
  • In the INSERT INTO statement of MySQL, you can insert single or multiple rows into the database table.
  • MySQL UPDATE statement, you can update the single row using the UPDATE & WHERE clause statement at a time.
  • The DELETE statement is used to remove/delete a specific row or multiple rows using the MySQL DELETE & WHERE clause.

Table Of Content

  • SELECT Statement MySQL
  • INSERT Statement MySQL
  • UPDATE Statement MySQL
  • DELETE Statement MySQL

SELECT Statement MySQL

In MySQL, The SELECT statement is the most commonly used MySQL statement. You can use the SELECT statement to fetch or get data from one or more tables within the database. With SELECT statement of MySQL, you can fetch all fields of table or specified fields.

Syntax

In MySQL SELECT statement syntax is :-

 SELECT field1, field2 … field n
 FROM Table  
 [WHERE conditions];  

Params

  • Fields :- It’s a database column name. You can fetch one or more fields using SELECT statement.
  • Table :- It’s a database table name.
  • WHERE :- It’s a option. If You want to filter some data that time specify any condition using the WHERE clause.

SELECT Statement Example

 SELECT users.id, users.name, users.age  
 FROM users  
 WHERE status = active;

INSERT INTO Statement MySQL

In MySQL, You can use the INSERT INTO statement to insert data to your database table. With INSERT INTO statement of MySQL, you insert single row or multiple rows into database table.

Syntax

In MySQL INSERT INTO statement syntax is :-

 INSERT INTO table_name ( field1, field2,…fieldN )  
 VALUES ( value1, value2,…valueN );  

Params

  • Fields :- It’s a database column name. You can insert value into in it.
  • table_name :- It’s a database table name.
  • Value :- It’s your column values, that you want to insert into database

INSERT INTO Statement Example

Here, we will insert single row into database table name users.

INSERT INTO users(id,name) VALUES (1, 'test');  

Here, we will insert multiple rows into database table name users.

INSERT INTO users  
 (id, first_name, last_name)  
 VALUES  
 (5, 'wis', 'check'),  
 (6, 'joy', 'son'),  
 (7, 'kemal', 'case');

UPDATE Statement MySQL

In MySQL, You can use the UPDATE statement to update or change data to your database table. With UPDATE statement of MySQL, you can change or modify table data by using MySQL WHERE Clause.

Syntax

In MySQL UPDATE statement syntax is :-

UPDATE table_name SET field1=new-value1, field2=new-value2  

[WHERE Clause]  

Params

  • table_name: – This is the name of a database table.
  • Fields: – This is a database column name. Where you can update the value in it
  • Value: – These are your column values, which you want to update in the database.
  • WHERE: – In MySQL, where the clause is used to update specific rows in a table.

UPDATE Statement Example

Here, we will update data into database table using UPDATE AND WHERE Clause statement of MySQL.

 UPDATE users
 SET first_name = 'Michel'
 WHERE id = 501;

DELETE Statement MySQL

In MySQL, You can use the DELETE statement to delete/remove all the data from database table.
You can delete/remove records single data from the databse table on the basis of conditions.

Syntax

In MySQL DELETE statement syntax is :-

DELETE FROM table_name;

OR

DELETE FROM table_name
[WHERE Clause]; 

Params

  • table_name: – This is the name of a database table.
  • WHERE: – In MySQL, where clause is used to delete specific rows in a database table.

DELETE Statement Example

Here, we will delete/remove data into database table using DELETE AND WHERE Clause statement of MySQL.

DELETE FROM users  
WHERE id = 15;  

DELETE All Record From Table Example

In MySQL, You can use the following syntax for delete all records from databse table.

DELETE FROM users;

Conclusion

In this MySQL Tutorial Point – We have learned a MySQL SELECT, INSERT INTO, UPDATE, DELETE query with syntax and example.

Recommended MySQL Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *