Writing MYSQL queries (SELECT, INSERT, UPDATE, DELETE)
MySQL queries for SELECT, INSERT, UPDATE, and DELETE operations.
SELECT Query:
Retrieve data from a database.
MYSQL code
SELECT column1, column2
FROM table_name
WHERE condition;
Example:
MYSQL code
SELECT first_name, last_name
FROM employees
WHERE department = 'IT';
INSERT Query:
Add new records to a database table.
MYSQL code
INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3);
Example:
MYSQL code
INSERT INTO customers (first_name, last_name, email)
VALUES ('Amit', 'Kumar', 'test@gmail.com');
UPDATE Query:
Modify existing records in a database table.
MYSQL code
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Example:
MYSQL code
UPDATE products
SET price = 12.99
WHERE product_id = 12;
DELETE Query:
Remove records from a database table.
MYSQL code
DELETE FROM table_name
WHERE condition;
Example:
MYSQL code
DELETE FROM products
WHERE order_id = 15;
Please note that in real-world applications, you would replace table_name with the actual name of the table in your database and provide appropriate column names, values, and conditions. Also, always exercise caution when using DELETE and UPDATE queries to avoid unintended data loss or modification.
Comments
Post a Comment