SQL -Structured Query Language - Sql Select - Select Record Tutorial
To retrieve or select the record of the existing created table with or without special condition. Then we can use a ' SELECT ' statement.
This is a very important query, which can be used in multiple ways.
Without condition
Syntax-
The basic syntax of the ‘ SELECT ‘ statement is given below –
SELECT [CONSTRAINT multiple_column_name or * ] FROM table_name;
Here * is used for all the columns in the table.
And we can also mention a specific column to retrieve data of that only column.
Constraint – Distinct, Unique, etc.
For example-
- Using *
SELECT * FROM employees;
Here it will select/retrieve all records from the employees table.
- Using specific column name
SELECT employee_id,first_name,salary FROM employees;
Here it will select/retrieve only employee_id, first_name, and salary from the employee table.
We can use whereas Condition / Clause in select statements such as WHERE, GROUP BY, HAVING, ORDER BY, ETC.
With condition (USING WHERE)
Syntax-
The basic syntax of the ‘ SELECT ‘ statement with the condition is given below –
SELECT [multiple_column_name or * ] FROM table_name WHERE [CONDITION];
For example-
- Using *
SELECT * FROM employee WHERE id = 100;
Here it will select/retrieve all columns from the Employees table whose id is 100.
- Using specific column name
SELECT employee_id,first_name,salary FROM employees WHERE employee_id = 100;
Here it will select/retrieve employee_id,first_name, and salary from the employee table whose employee_id is 100.