Basic SQL Queries Using Default Database Northwind... Step by Step Tutorial

Basic SQL Queries:

We use the default database of northwind to explain the 'Basic Queries of SQL'.
You can download northwind database from: Download

Learn How to Attach .mdf File of database

A SELECT indicates that we are merely reading information, as opposed to modifying it. What where selecting is identified by an expression or column list immediately following the SELECT. The FROM statement specifies the name of the table or tables from which we are getting our data.


SELECT <column list>
[FROM <source table(s)>]

Example 1

Select * from Employees;

The above query Selects all the employees records from the data base and displays its columns.

 Example 2

Select FirstName, LastName from Employees;

The above query Selects data of these two columns from the Employees table
Then there are some functions that can be used in select statement syntax is
SELECT function(<column list>)
[FROM <source table(s)>]

Function are SUM, COUNT, DISTINCT, AVG, MIN and MAX there are many other function that are also available.

Example 3

SELECT CustomerID, EmployeeID, COUNT(*)
FROM Orders;


SELECT function(<column list>)
[FROM <source table(s)>]

The WHERE clause immediately follows the
FROM clause and defines what conditions a record has to meet before it will be shown.

Example 4

SELECT Name, ProductNumber, ReorderPoint
FROM Production.Product
WHERE ProductID = 356

1- Get Order id, product id, unit price from Order Details.

select OrderID,ProductID,UnitPrice from dbo.[Order Details];

2- Count total number of employees.

select COUNT(EmployeeID)AS Number from Employees;

3- Get the most expensive product amount from Products.

select Max (UnitPrice) from dbo.Products

4- Multiply unit price to quantity in OrderDetails to get   OrderPrice.

select UnitPrice * Quantity AS OrderPrice from dbo.[Order Details];

5- Display all cities that employees belong to but don’t allow repetition.

select Distinct City from dbo.Employees

6- Display the complete name of all the employees.

select FirstName+LastName As CompleteName from dbo.Employees

7- Display data of all employees those working as Sales Representative.

select * from dbo.Employees where Title = 'Sales Representative';

8- Display the CustomerID of customers whose order is shipped to London and display the column name as CustomerID_London.

select CustomerID As CustomerID_London from dbo.Customers  where City = 'London'

Thank you for reading hope it will help you if you have any problem with above articles comment below we will try to help you.

Commenting on a post is a great way to show some love for what you're seeing.