SQL Tutorial
to use
SELECT, WHERE, Order
by, INSERT, NULL
Functions
By
Avjinder Kaler
(askaler@uark.edu)
SQL is a standard language for storing,
manipulating and retrieving data in databases.
SELECT function for selection purpose in the Table.
• When someone want to select all the columns from the
Customers table.
SELECT * FROM Customers;
* for all columns
• When you want to select only one column, for example the City
column, from the Customers table.
SELECT City FROM Customers;
• When you want to select different values from the Country
column in the Customers table.
SELECT DISTINCT Country FROM Customers;
Where function for selection purpose at specific
place in the Table.
• When you want to select a specific value in a specific column, for
example the "Berlin" value from the City column in the
Customers table.
SELECT * FROM Customers
WHERE City = 'Berlin';
• When you want to select all values other than one specific value
in a specific column, for example the "Not Berlin" value from the
City column in the Customers table.
SELECT * FROM Customers
WHERE City <> 'Berlin';
* These are different operator to use.
• When you want to select one specific number value in a specific
column, for example the "32" value from the CustomerID
column in the Customers table.
SELECT * FROM Customers
WHERE CustomerID = 32;
• When you want to select records from two columns, for example
Berlin value from City column and the value 12209 from
PostalCode column in the Customers table.
SELECT* FROM Customers
WHERE City = 'Berlin'
AND PostalCode = 12209;
• When you want to select two different records from the same
column, for example the value Berlin and the value London from
the City column in the Customers table.
SELECT * FROM Customers
WHERE City = 'Berlin'
OR City = 'London';
Order by function for sorting the records in the
columns in the Table.
• When you want to sort the records alphabetically in a specific
column, for example records in the City column in the Customers
table.
SELECT * FROM Customers
ORDER BY City;
• When you want to sort the records reverse alphabetically in a
specific column, for example records in the City column in the
Customers table.
SELECT * FROM Customers
ORDER BY City DESC;
• When you want to sort the records in two columns, first one
column and then second after that, for example first by the
column Country, then, by the column City in the Customers
table.
SELECT * FROM Customers
ORDER BY Country, City;
Insert function for inserting new records in the
columns in the Table.
• When you want to insert new values the records in different
columns, for example 'Hekkan Burger', ‘Gateveien 15', 'Sandnes',
'4306', 'Norway' new values in the CustomerName, Address,
City, PostalCode, Country columns, respectively, in the
Customers table.
INSERT INTO Customers (
CustomerName,
Address,
City, Columns where new records will be inserted
PostalCode,
Country)
VALUES (
'Hekkan Burger',
'Gateveien 15',
'Sandnes', new records/values
'4306',
'Norway');
Null function for inserting new records in the
columns in the Table.
• When you want to select all empty records from a specific
column, for example empty records in the PostalCode column in
the Customers table.
SELECT * FROM Customers
WHERE PostalCode IS NULL;
• When you want to select all non-empty records from a specific
column, for example non-empty records in the PostalCode
column in the Customers table.
SELECT * FROM Customers
WHERE PostalCode IS NOT NULL;

Sql tutorial for select, where, order by, null, insert functions

  • 1.
    SQL Tutorial to use SELECT,WHERE, Order by, INSERT, NULL Functions By Avjinder Kaler (askaler@uark.edu) SQL is a standard language for storing, manipulating and retrieving data in databases.
  • 2.
    SELECT function forselection purpose in the Table. • When someone want to select all the columns from the Customers table. SELECT * FROM Customers; * for all columns • When you want to select only one column, for example the City column, from the Customers table. SELECT City FROM Customers; • When you want to select different values from the Country column in the Customers table. SELECT DISTINCT Country FROM Customers;
  • 3.
    Where function forselection purpose at specific place in the Table. • When you want to select a specific value in a specific column, for example the "Berlin" value from the City column in the Customers table. SELECT * FROM Customers WHERE City = 'Berlin'; • When you want to select all values other than one specific value in a specific column, for example the "Not Berlin" value from the City column in the Customers table. SELECT * FROM Customers WHERE City <> 'Berlin'; * These are different operator to use.
  • 4.
    • When youwant to select one specific number value in a specific column, for example the "32" value from the CustomerID column in the Customers table. SELECT * FROM Customers WHERE CustomerID = 32; • When you want to select records from two columns, for example Berlin value from City column and the value 12209 from PostalCode column in the Customers table. SELECT* FROM Customers WHERE City = 'Berlin' AND PostalCode = 12209; • When you want to select two different records from the same column, for example the value Berlin and the value London from the City column in the Customers table. SELECT * FROM Customers WHERE City = 'Berlin' OR City = 'London';
  • 5.
    Order by functionfor sorting the records in the columns in the Table. • When you want to sort the records alphabetically in a specific column, for example records in the City column in the Customers table. SELECT * FROM Customers ORDER BY City; • When you want to sort the records reverse alphabetically in a specific column, for example records in the City column in the Customers table. SELECT * FROM Customers ORDER BY City DESC; • When you want to sort the records in two columns, first one column and then second after that, for example first by the column Country, then, by the column City in the Customers table. SELECT * FROM Customers ORDER BY Country, City;
  • 6.
    Insert function forinserting new records in the columns in the Table. • When you want to insert new values the records in different columns, for example 'Hekkan Burger', ‘Gateveien 15', 'Sandnes', '4306', 'Norway' new values in the CustomerName, Address, City, PostalCode, Country columns, respectively, in the Customers table. INSERT INTO Customers ( CustomerName, Address, City, Columns where new records will be inserted PostalCode, Country) VALUES ( 'Hekkan Burger', 'Gateveien 15', 'Sandnes', new records/values '4306', 'Norway');
  • 7.
    Null function forinserting new records in the columns in the Table. • When you want to select all empty records from a specific column, for example empty records in the PostalCode column in the Customers table. SELECT * FROM Customers WHERE PostalCode IS NULL; • When you want to select all non-empty records from a specific column, for example non-empty records in the PostalCode column in the Customers table. SELECT * FROM Customers WHERE PostalCode IS NOT NULL;