MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
lcxz
V2EX  ›  MySQL

查询多值不去掉重复

  •  
  •   lcxz · Mar 6, 2020 · 3324 views
    This topic created in 2262 days ago, the information mentioned may be changed or developed.

    id key val

    1 1 10

    2 2 20

    ...

    8 8 80

    select * from a where key in(1,2,1,5,2,8)

    查询结果:1,2,5,8 记录

    但我想要:1,2,1,5,2,8 记录

    3 replies    2020-03-06 14:03:06 +08:00
    opengps
        1
    opengps  
       Mar 6, 2020
    同一个表,union 5 次得出这 6 个结果
    这类行重复需求尽量放到业务层用程序处理,数据库尽可能只执行最简单的逻辑
    Sasasu
        2
    Sasasu  
       Mar 6, 2020
    首先你不该用 IN,没有一个数据库喜欢。

    应该用 join on A.id = B.id
    af463419014
        3
    af463419014  
       Mar 6, 2020
    你是 PM 派过来的奸细吗,为什么要跟 PM 一样提这种反人类的需求
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3904 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 90ms · UTC 00:10 · PVG 08:10 · LAX 17:10 · JFK 20:10
    ♥ Do have faith in what you're doing.