Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SELECT Command in Sql server


SQL Tutorial
SQL stands for Structured Query Language is used to modify and access data or information from a storage area called Database.

History of SQL Database Design

It was introduced first by IBM in 1970s.and it is an ANSI/ISO standard. Soon it becomes a Standard Language used by relational database management systems (RDBMS) such as Oracle, Microsoft SQL server, Sybase etc.
SQL is Divide in Different Languages:-
1)DML(Data Manipulation Language) – Select , Insert , Delete , Update
2)DDL (Data Definition Language)- Create, Alter, Drop
3)DCL(Data Control Language)- Grant , Revoke

SQL Database Table

Database -> IS collection of tables .Database itself to capture and analyze data

SQL Database Table Columns

Table consist of Multiple Table . Column is also know as entity.

SQL Database Table Rows

Each SQL table row, referred to a record, is located in the left column of the table. Sql record row will contain a string of data containing data matching up to each column field across the top.

SQL Select Statement

Syntax of SQL SELECT Statement:

SELECT column_listFROM table-name
[WHERE Clause]
[GROUP BY clause]
[HAVING clause]
[ORDER BY clause];

Select * from tbl_employee

Concatenate two column in Sql

Select firstname +’’+lastname from tbl_employee;

SQL Alias

Sql Alias means create second name to a column
Select firstname as First from tbl_employee
SQL Where
Where clause is use when we have to see the data depends on a condition
Select * from tbl_employee where firstname=’Nick’
Sql Operator
There are two type of operator Comparison Operators and Logical Operators. These operators are used WHERE clause, HAVING clause to filter the data to be selected.

Comparison Operators:

It is used to compare the column data with specific values in a condition.
Comparison Operators
Description
=
equal to
, !=
is not equal to
less than
>
greater than
>=
greater than or equal to
less than or equal to

 

Logical Operators:

There are three Logical Operators namely AND, OR and NOT.
i.e 1)Select * from tbl_employee where doj >=getdate();
2)Select * from tbl_emplyee where firstname=’nick’ and department=’Admin’;

SQL Comparison Keywords

There are many operator "IN", "BETWEEN...AND", "IS NULL", "LIKE".
Comparision Operators
Description
LIKE
column value is similar to specified character(s).
IN
column value is equal to any one of a specified set of values.
BETWEEN...AND
column value is between two values, including the end values specified in the range.
IS NULL
column value does not exist.

Like Operator is used to search a data that belongs to a Particular Pattern.
i.e.
1)Select * from tbl_employee where firstname like ‘%Nick%’
It will show the data whose name start with Nick
2)Select * from tbl_employee where department in(‘Admin’,’Teacher’,’Student’);
It show the data of those employee which belongs to Admin , Teacher, Student
3)Select * from tbl_employee where dob between ‘2016-01-01’ and ‘2016-07-18’;
It show the data of those employee whose dob is between 2016-01-01’ and ‘2016-07-18’
4)Select * from tbl_employee where department is null;
It show the data of those employee whose department is null
5)Select * from tbl_employee where department is not null;
It show the data of those employee whose department is not null
6)Select * from tbl_employee where department not in(‘Admin’,’Teacher’,’Student’);
It show the data of those employee which not belongs to Admin , Teacher, Student

SQL ORDER BY

ORDER BY clause is used in a SELECT statement to sort results either in ascending or descending order.
SELECT column-list
FROM table_name [WHERE condition]
[ORDER BY column1 [, column2, .. columnN] [DESC]];
Select * from tbl_employee where order by firstname desc



This post first appeared on Pivot In SQL Server, please read the originial post: here

Share the post

SELECT Command in Sql server

×

Subscribe to Pivot In Sql Server

Get updates delivered right to your inbox!

Thank you for your subscription

×