TechSapphire Tuesday, 2024-03-19, 11:40 AM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • SQL for Beginners

    SQL (Structured Query Language)

    • It is high level language which provide you capability to query data from any structured data source (Tables). 
    • High level language means language which is used by us to communicate (English). 
    • For learning, we will be using online SQL editor provided by W3C.
    • http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all

    SQL script:

    SQL Queries:

    Using Wild Card (*) :
    Selecting all data 
    SELECT * FROM CUSTOMERS

    Specific Columns:
    SELECT CustomerName, ContactName,Address,
     City FROM CUSTOMERS

    Playing with data:
    Joining 2 Columns:
    Select CustomerName,ContactName,Address + ' - ' + City 
    FROM CUSTOMERS

    Using Alias:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address] 
    FROM CUSTOMERS

    Using WHERE Clause:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address]
    FROM CUSTOMERS WHERE City='Berlin'

    Playing with WHERE:
    OR Clause:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address]
    FROM CUSTOMERS WHERE City='Berlin' OR City='London'

    AND Clause:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address]
    FROM CUSTOMERS WHERE City='London' AND Postalcode='WA1 1DP'

    Like Clause:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address],PostalCode
    FROM CUSTOMERS WHERE Postalcode like 'W%'

    IN Clause:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address],PostalCode
    FROM CUSTOMERS WHERE City IN ('Berlin','London')

    Precedence:
    Select CustomerName,ContactName,
    Address + ' - ' + City AS [Address],PostalCode
    FROM CUSTOMERS 
    WHERE (City='London' AND Postalcode='WA1 1DP') OR City='Berlin'

    Group By:
    Select City,Count(*)
    FROM CUSTOMERS  GROUP BY City

     

    Playing more:
    Grouping by Country and City:

    Select Country,City,Count(*)
    FROM CUSTOMERS  GROUP BY Country,City

    Error Queries:
    SELECT SupplierID,count(1) from Products

    Query:
    SELECT SupplierID,count(1) from Products GROUP BY SupplierID

    Query:
    SELECT SupplierID,CategoryID,count(1) from Products
     group by SupplierID,CategoryID ORDER BY SupplierID 


    HAVING Clause:
    SELECT SupplierID,count(1) from Products GROUP BY SupplierID HAVING Count(1)>2

    Click here to download files/SQL_for_Beginner.zip

     

    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2024