WikiGalaxy

Personalize

SQL SELECT Statement

Basic SELECT Query:

The SELECT statement is used to query the database and retrieve data from one or more tables. It’s the most commonly used SQL command.


SELECT column1, column2 FROM table_name;
    

Example:

Retrieve the first name and last name of all employees:


SELECT first_name, last_name FROM employees;
    

SQL WHERE Clause

Filtering Data:

The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition.


SELECT column1, column2 FROM table_name WHERE condition;
    

Example:

Find all employees in the 'Sales' department:


SELECT * FROM employees WHERE department = 'Sales';
    

SQL INSERT INTO Statement

Adding New Records:

The INSERT INTO statement is used to add new rows of data to a table.


INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
    

Example:

Add a new employee record:


INSERT INTO employees (first_name, last_name, department) VALUES ('John', 'Doe', 'Marketing');
    

SQL UPDATE Statement

Modifying Existing Records:

The UPDATE statement is used to modify existing records in a table.


UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
    

Example:

Update the department of an employee:


UPDATE employees SET department = 'HR' WHERE employee_id = 101;
    

SQL DELETE Statement

Removing Records:

The DELETE statement is used to remove existing records from a table.


DELETE FROM table_name WHERE condition;
    

Example:

Delete an employee record:


DELETE FROM employees WHERE employee_id = 102;
    

SQL JOIN Clause

Combining Tables:

The JOIN clause is used to combine rows from two or more tables, based on a related column between them.


SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;
    

Example:

Join employees and departments tables to get employee names with their department names:


SELECT employees.first_name, departments.department_name
FROM employees
INNER JOIN departments ON employees.department_id = departments.id;
    

SQL GROUP BY Clause

Aggregating Data:

The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".


SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name;
    

Example:

Count the number of employees in each department:


SELECT department, COUNT(*)
FROM employees
GROUP BY department;
    

SQL ORDER BY Clause

Sorting Data:

The ORDER BY keyword is used to sort the result-set in ascending or descending order.


SELECT column1, column2 FROM table_name ORDER BY column1 ASC|DESC;
    

Example:

List all employees ordered by their last name:


SELECT first_name, last_name FROM employees ORDER BY last_name ASC;
    
logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025