Select, Insert, Update, Delete Query in MySQL

Mysql insert, update, delete query; Through this tutorial, i am going to show you how to use MySQL SELECT, INSERT INTO, UPDATE, DELETE with the help of examples.

Select, Insert, Update, Delete Query in MySQL

Use the following mysql statements to insert, update, delete data from mysql database tables; as follows:

  • 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 of MySQL SELECT statement syntax is :-

 SELECT field1, field2 … field n
 FROM Table  
 [WHERE conditions];  
  • 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.

Example 1 – MySQL SELECT Query

 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 of MySQL INSERT INTO statement syntax is :-

 INSERT INTO table_name ( field1, field2,…fieldN )  
 VALUES ( value1, value2,…valueN );  
  • 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

Example 1 – INSERT INTO Query

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 of MySQL UPDATE statement syntax is :-

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

[WHERE Clause]  
  • 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.

Example 1 – MySQL UPDATE Query

 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 of MySQL DELETE statement syntax is :-

DELETE FROM table_name;

OR

DELETE FROM table_name
[WHERE Clause]; 
  • 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.

Example 1 – MySQL DELETE Query

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

MySQL select, insert, update and query example tutorial, you have learned how to use MySQL SELECT, INSERT INTO, UPDATE, DELETE.

Leave a Comment