Data Analytics
SQL Basics - The Select Statement
SQL is an an abbreviation for Structured Query Language. SQL is made up of very few words to provide simple and efficient way to read and write data from database. The sequence of SELECT clauses is mentioned below. These are all some of the SQL reserved words to retrieve the data.
- SELECT
- FROM
- WHERE
- GROUP BY
- HAVING
- ORDER BY
Note - SQL is not case sensitive
Example Table - Students
student-id | student _name | gender | Attendance | Age | location | Class | section | Contact _no | CGPA |
1AB21 | Aman | Male | 56.23 | 15 | Bangalore | 9 | A | 7654321120 | 7.9 |
2AB22 | Bhavana | Female | 89.65 | 17 | Mangalore | 10 | B | 9876543210 | 9.3 |
1AB23 | Arjun | Male | 56.23 | 15 | Bangalore | 9 | A | 7654325454 | 9.9 |
2AB24 | Bhuvan | Male | 69.65 | 16 | Mysore | 10 | B | 9876543989 | 8.3 |
1AB25 | Amala | Female | 76.23 | 15 | Bangalore | 9 | A | 7657654120 | 6.9 |
2AB26 | Bhavya | Female | 59.65 | 13 | Mandya | 8 | B | 9876567543 | 9.3 |
Explanation
CLAUSE | SYNTAX | Example | Explanation |
SELECT | SELECT (Col_ name) | SELECT (student_ name ) | When specific columns are to be retrieved from a dataset. |
FROM | FROM ( Table_ name) | FROM ( Students ) | From which table the fields(columns) are to be retrieved. |
WHERE | WHERE ( condition for specific rows) | WHERE ( attendance > 80 ) | The rows that satisfy the given condition. |
GROUP BY | GROUP BY (Col_ name) | GROUP BY ( gender ) | Grouping the rows based on a column name. |
HAVING | HAVING ( condition for specific groups) | HAVING ( cgpa > 7 ) | The groups that satisfy the given condition. |
ORDER BY | ORDER BY ( Col_ name) | ORDER BY ( student _ id) | Sorting the output in ascending order. |
Output
Bhavana
As she is the only student having cgpa > 7 and attendance > 80
This is the simplest explanation for the sequence of the execution of the select statement in SQL.
- Sangeetha Rani S
- Dec, 27 2022
Add New Comments
Please login in order to make a comment.