zoukankan      html  css  js  c++  java
  • SQL学习——基本语法

    以下是一些主要的SQL语句的语法实例

    SELECT(查询某列)
    SELECT column_name(s)
    FROM table_name
    
    SELECT DISTINCT(消除重复的元组)
    SELECT DISTINCT column_name(s)
    FROM table_name
    
    SELECT *    (查询表中的所有数据)
    SELECT *
    FROM table_name
    
    WHERE(范围限定)    
    SELECT column_name(s)
    FROM table_name
    WHERE column_name operator value
    
    LIKE    (匹配查询,注意:有5种通配符)
    SELECT column_name(s)
    FROM table_name
    WHERE column_name LIKE pattern
    
    ORDER BY (排序:ASC升序,DESC降序)
    SELECT column_name(s)
    FROM table_name
    ORDER BY column_name [ASC|DESC]
    
    INNER JOIN(内连接)
    SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2 
    ON table_name1.column_name=table_name2.column_name
    
    LEFT JOIN    (左外连接)
    SELECT column_name(s)
    FROM table_name1
    LEFT JOIN table_name2 
    ON table_name1.column_name=table_name2.column_name
    
    RIGHT JOIN(右外连接)
    SELECT column_name(s)
    FROM table_name1
    RIGHT JOIN table_name2 
    ON table_name1.column_name=table_name2.column_name
    
    FULL JOIN    (全外连接)
    SELECT column_name(s)
    FROM table_name1
    FULL JOIN table_name2 
    ON table_name1.column_name=table_name2.column_name
    
    INSERT INTO    (插入数据)
    INSERT INTO table_name
    VALUES (value1, value2, value3,....)
    or
    INSERT INTO table_name
    (column1, column2, column3,...)
    VALUES (value1, value2, value3,....)
    
    UPDATE    (修改数据)
    UPDATE table_name
    SET column1=value, column2=value,...
    WHERE some_column=some_value
    
    DELETE (删除数据)
    DELETE FROM table_name
    WHERE some_column=some_value
    or
    DELETE FROM table_name 
    (Note: Deletes the entire table!!)
    
    DELETE * FROM table_name 
    (Note: Deletes the entire table!!)
  • 相关阅读:
    mysql中的内置函数
    python之旅九【第九篇】socket
    docker的安装,升级,与删除(最新版)
    consul与docker的使用
    python之旅第八篇--异常
    python的图形模块PIL小记
    python之旅七【第七篇】面向对象之类成员
    python之旅六【第七篇】面向对象
    zabbix上监控docker
    zabbix在ubuntu16.04上的安装
  • 原文地址:https://www.cnblogs.com/liuliang1999/p/10340068.html
Copyright © 2011-2022 走看看