fbpx

SQL Basics – Examples

Basic Select Statments
Arithmetic Operators
Column Aliases
String Concat
Distinct
Basic Where
In Operator
Between Operator
Like Operator
Is Null
And Or
Order By
Top
Scalar Functions
String Functions
Numeric Functions
Date Functions
Conversion Functions
Null Related Functions
Conditional Logic
Group Functions
Group By
Having
Basic Join
Join More Than 2 Tables
Outer Join
Self Join
Single Row Sub Queries
Multiple Row Sub Queries

Basic Select Statments

-------------------------------
-- SQL Server SELECT Statement
-------------------------------
-- 1. About ACDB Database 

-- 2. Basic Select Statement
SELECT * 
FROM customers 


-- * The SQL Server SELECT clause:
--   Lets you choose what you want to display.
-- * The asterisk sign (*) indicates that you want to select all fields contained in this table.
-- * The SQL Server FROM clause:
--   Lets you specify from which table you want to retrieve all of these fields.
-- * A table’s name always appears after the FROM keyword.

-- 3. Selecting Specific Columns
SELECT customer_id, last_name, city, city
FROM customers 


-- * The SQL Server SELECT clause:
--   Lets you choose what columns you want to display (“Projection”).
-- * After the SQL Server SELECT keyword, specify the names of the columns that you would like to 
--   retrieve, separated by comma (,).
-- * You can specify as many columns as you want; you can even specify the same column more than once.
-- * The columns appear in the order selected.

-- 4. General Guidelines
-- * In each SQL statement, SQL Server SELECT and FROM clauses are mandatory. 
-- * The order of the SQL Server SELECT and FROM clauses cannot be changed.
-- * It is possible to specify a column’s name multiple times
-- * To enhance readability – even though the SQL Server SQL syntax is neither case-sensitive, 
--   nor sensitive to spaces or line breaks, ensure writing in an orderly manner: 
--   write the keywords in capital letters, names of columns/tables in small letters, 
--   insert a line break after each command and indents when required.

SELEct CUSTomer_ID                , CITY


fROM          cUSTOMERS 

Arithmetic Operators

To read more

UpScale Analytics is one of the largest platforms in the world for learning SQL by doing, consisting over 300 SQL exercises at different levels (including solutions), by topics, across over 100 different datasets. More…