• MySQL 高级


    # 可能插入重复数据的 SQL 语句

    解决方法:

    1. REPLACE
    2. INSERT ... ON DUPLICATE KEY
    REPLACE [LOW_PRIORITY | DELAYED]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        [(col_name,...)]
        {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
    
    REPLACE [LOW_PRIORITY | DELAYED]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        SET col_name={expr | DEFAULT}, ...
    
    REPLACE [LOW_PRIORITY | DELAYED]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        [(col_name,...)]
        SELECT ...
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        [(col_name,...)]
        {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
        [ ON DUPLICATE KEY UPDATE
          col_name=expr
            [, col_name=expr] ... ]
    
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        SET col_name={expr | DEFAULT}, ...
        [ ON DUPLICATE KEY UPDATE
          col_name=expr
            [, col_name=expr] ... ]
    
    INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name,...)]
        [(col_name,...)]
        SELECT ...
        [ ON DUPLICATE KEY UPDATE
          col_name=expr
            [, col_name=expr] ... ]

    Reference:

    https://dev.mysql.com/doc/refman/5.7/en/replace.html REPLACE Syntax

    https://dev.mysql.com/doc/refman/5.7/en/insert.html INSERT Syntax

    # FULL OUTER JOIN 

    MySQL 不支持 FULL OUTER JOIN。

    解决方法:

    左连接 + 右连接。

    select * from A LEFT JOIN B on A.id = B.id 
    union
    select *from A RIGHT JOIN B on A.id = B.id;

    Reference:

    http://www.cnblogs.com/liuyifan/p/4985512.html

  • 相关阅读:
    实现centos系统的自动化安装部署
    加密与CA证书的创建
    Linux系统启动和内核管理
    进程,系统性能和计划任务
    第十七周运维作业
    第十六周运维作业
    第十四周运维作业
    第十三周运维作业
    第十二周运维作业
    第十一周运维作业
  • 原文地址:https://www.cnblogs.com/Piers/p/6552819.html
Copyright © 2020-2023  润新知