Seele

Seele

SQL Data Manipulation Language

Data Insertion, Deletion, Modification#

  1. Insertion
    INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)
    
  2. Deletion
     DELETE FROM table_name WHERE column_name = value
    
  3. Modification
     UPDATE table_name SET column_name = New_value WHERE column_name = Old_value
    
  4. Query
     SELECT column_name FROM table_name WHERE column_name = value
    

Simple Query, Join Query#

  1. Simple Query

    SELECT column_name(s) FROM table_name
    
  2. Join Query

    mysql Union

    SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 
    // UNION DISTINCT combines two or more queries into one result set and removes duplicate data (keeping one copy),
    // equivalent to UNION without DISTINCT
    // UNION ALL keeps all data (then why use UNION?)
    

    Tips:

    1. The "*" symbol can replace fields
    2. Where contains conditions after it
    3. Conditions can be connected using AND or OR
    4. LIMIT can be used to limit the length of the result set
    5. OFFSET can be used to specify the offset of the result set (where to start)
    6. COUNT(*) can retrieve the number of rows in the result set
  3. Nested Subquery

    SELECT column_name(s) FROM table_name WHERE column_name(s) 
    IN 
    (
        SELECT column_name(s) FROM table_name WHERE column_name(s) = value
     )
    

Sorting, Calculating, Grouping Query Results#

  1. Sorting

    SELECT column_name(s) FROM table_name ORDER BY column_name(s) [ASC|DESC]
    // ASC ascending (default), DESC descending
    WHERE column_name(s) 
     LIKE    value
    //% in the value after like can replace any character
    
    
  2. Calculating

    FunctionDescriptionExample
    AVGCalculate the average valueAVG(column_name(s))
    COUNTCalculate the total number of query recordsCOUNT(column_name(s))
    MAXCalculate the maximum valueMAX(column_name(s))
    MINCalculate the minimum valueMIN(column_name(s))
    SUMCalculate the sumSUM(column_name(s))
    MODCalculate the remainderMOD(column_name(s),value)
    STDCalculate the standard deviationSTD(column_name(s))
    RANDCalculate random numberRAND()
    ROUNDCalculate roundingROUND(column_name(s),value)
    GREATESTCalculate the maximum valueGREATEST(column_name(s),column_name(s))
    LEASTCalculate the minimum valueLEAST(column_name(s),column_name(s))

    Tips:

    1. Difference between MAX and GREATEST functions
    2. Standard deviation is the square root of variance.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.