Practical – 97 : MY SQLમાં Simple Select Queriesનો ઉપયોગ કરવો.
Example 1: Selecting Specific Columns
Retrieve only first_name and last_name columns
SELECT first_name, last_name
FROM employees;
This example retrieves the first_name and last_name columns from the employees table.
Output:
+————+———–+
| first_name | last_name |
+————+———–+
| John | Doe |
| Jane | Smith |
| Robert | Johnson |
+————+———–+
Explanation:
- The query retrieves the first_name and last_name columns from the employees table.
- The result set displays the names of all employees in the table.
Example 2: Selecting All Columns
This query will retrieve the entire employee table.
SELECT * from employees;
Output:
+————-+————+———–+——–+
| employee_id | first_name | last_name | salary |
+————-+————+———–+——–+
| 1 | John | Doe | 50000 |
| 2 | Jane | Smith | 60000 |
| 3 | Robert | Johnson | 75000 |
+————-+————+———–+——–+
Example 3: Performing Arithmetic Operations
SELECT 32*32
Output:
+——-+
| 32*32 |
+——-+
| 1024 |
+——-+
We can also use SELECT statements to perform, basic mathematical operations.
MySQL SELECT DISTINCT Statement
MySQL SELECT DISTINCT Statement is used to retrieve only distinct data from a field/column.
It is very used to remove duplicates from the results.
Syntax:
SELECT DISTINCT column1, column2, …
FROM table_name
The MySQL SELECT statement is crucial for fetching specific data from tables, whether retrieving entire rows or selected columns. It supports filtering with WHERE, sorting with ORDER BY, and limiting results with LIMIT. Additionally, SELECT can perform calculations and handle distinct values with SELECT DISTINCT, making it versatile for various database querying needs.