› 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
displayabc
V2EX  ›  MySQL

怎么把 MySQL 多个表当作一个表查询?

  •  
  •   displayabc · Jul 3, 2014 · 5337 views
    This topic created in 4474 days ago, the information mentioned may be changed or developed.
    我有100张结构相同的表,只是数据不同,我怎么能把这100张表当作一张表来查询?
    12 replies  •  2014-07-03 15:39:23 +08:00
    robertlyc
        1
    robertlyc  
       Jul 3, 2014
    多态
    displayabc
        2
    displayabc  
    OP
       Jul 3, 2014
    @robertlyc 我是指在写SQL的时候
    plprapper
        3
    plprapper  
       Jul 3, 2014
    既然做了分表切分 必然是限定不存在跨表 group by order by 一类的需求 。
    不知道LZ 是要打破这个界限呢 ,还是说 如果抽象DAO REPO层 一类的需求呢。
    sivacohan
        4
    sivacohan  
       Jul 3, 2014 via Android
    你是要view吧?
    ipconfiger
        5
    ipconfiger  
       Jul 3, 2014
    map-reduce
    dong3580
        6
    dong3580  
       Jul 3, 2014   ❤️ 1
    存储过程或者view,推荐存储过程,view的话每次都要更新,浪费。
    Navee
        7
    Navee  
       Jul 3, 2014   ❤️ 1
    视图
    create view v_table as
    select t1.* from table1 t1
    union all
    select t2.* from table2 t2;

    select * from v_table;

    你要的是这样的吧?
    displayabc
        8
    displayabc  
    OP
       Jul 3, 2014
    @Navee 但是有些数据是重复的,比如每个表里都有id,这在每个表里都是自增的
    Navee
        9
    Navee  
       Jul 3, 2014
    @haython 查询视图的时候加上rownum就行了吧.
    Navee
        10
    Navee  
       Jul 3, 2014
    @dong3580 很想知道存储过程怎么实现这个.
    qqjt
        11
    qqjt  
       Jul 3, 2014 via Android
    唔,合成一个表不好么
    wingoo
        12
    wingoo  
       Jul 3, 2014
    一些基本的业务都没说
    1.分表的时候你有按照一定规则吧?
    2.你的查询条件是什么,和分表规则有无关联

    如果关联很少,可以构建些 冗余信息/冗余表 来记录这些信息
    或者干脆别拆。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2308 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 09:39 · PVG 17:39 · LAX 02:39 · JFK 05:39
    ♥ Do have faith in what you're doing.