select statement in sql Best ways

SQL SELECT Statement

select statement in sql The SQL SELECT is used to retrieve facts , information, and data from a database. The statistics returned are saved in an end result table called the result set.

In this article, we will see select statement in sql in detail, with the ability to select all rows and select specific rows and columns in database tables

below is the syntax for select statement in sql

SELECT column1, column2, ...FROM table_name;

The SELECT keyword is used to retrive or fetch the data from the database tables. or we can say that SELECT is the keyword used to write the data fetch query.
The column1, column2, … Are the names of the columns that you want to retrieve from the desk.
The table_name is the call of the desk that you want to retrieve the data from.

You can also use the * symbol to pick out all the columns from the desk.

For example, the following assertion might choose all the columns from the Customers table:

select EmployeeID,EmployeeName,EmployeeAddress,EmployeeCity from Employee

The SELECT statement can also be used to clear out the records that is lower back.

SQL Select

select statement in sql

Select Statements Select statements are used in sql to view data in tables or to display data between tables
Suppose you want to bring specific data from a table, you have to write a query like Select * From Table
here select is the SQL command or statement

STAR (*) means all rows and columns data in table
FROM is the syntax from where you want to retrive data
TableName is the name of your database table from which you want to retrive or fetch the data

Suppose You have a database EMPDB and in that database there is a table named Employee

Retrive All column in sql

you want to see all data from that employee table then you can write Select SQL statement

Select * from Employee

We have seen that how to retrieve all the columns in the table, now let’s see how to retrieve the specific column in the table

Retrive Specific Column in sql

suppose you only need 4 columns in the employee table such as EmployeeName,EmployeeID,EmployeeAddress,EmployeeSalary

To retrive specific column from table use below syntax

Select Column1,Column2,Column3,Column.N, from TableName
select EmployeeID,EmployeeName,EmployeeAddress,EmployeeCity from Employee

Here you will see the full data of the specific column you have selected in the Employee Table.
That is, all the data contained in The Table will look like the given column, employeeName, employeeID, employeeAddress, employeeSalary

select specific columns in sql
select specific columns in sql server

suppose you only need the above four columns whos address is mumbai, then you have to use the where clause.
The WHERE clause is used apply conditions and to filter the data from tables.

suppose you only need the above four columns whos address is mumbai, then you have to use the where clause.

Where Clause is used to filter the data while fetching records from table, if you want to records with specific date or cut of date (as on date) then you can use where clause to date column in table. below are the some examples of where clause

To use Where clause You need to know operators like =,>,<,>=,<=,<>, in , Not in ,like , between, exist, any,AND , OR, NOT

To see SQL Operators in details click here.

below is the syntax for the WHERE Clause

WHERE Clause

SELECT column1, column2, ... FROM table_name WHERE Condition;

For example, the following assertion would select all the clients whose city is “London”:

SELECT * FROM Employee WHERE City = 'Mumbai';

SELECT * FROM Employee WHERE EmployeeCity = 'Pune';
select EmployeeID,EmployeeName,EmployeeAddress,EmployeeCity
from Employee where EmployeeCity='Mumbai'

select * from Employee where EmployeeDOB='07-Oct-1975;
select specific with where condition
select specific columns with where condition

ORDER BY clause

The SELECT declaration can also be used to order the facts that is returned.

The ORDER BY clause is used to order the columns data.

below is the syntax for the ORDER BY Clause

ORDER BY column_name ASC /DESC
SELECT * FROM Employee WHERE EmployeeCity = 'Pune' order by EmployeeID  DESC

The column_name is the name of the column which you want to order the records via. the ASC keyword is used to order the facts in ascending order.

You can learn sql from Microsoft

https://learn.microsoft.com/

The DESC key-word is used to reserve the information in desc
ASC Keyword is used to order the data in ascending order
DESC Kayword is used to order the data in descending order
in above Example we have arranged EmployeeId in Descending order by using Order by clause

Leave a Comment