有15个tables ,column都是一样的 id , images 想从15个tables 中 随机输出15条数据 ,指定一个 table 只能一条数据. 简单说就是去table1 随机拿一条,再去table2 随机一条,以此类推 ... 语句该怎么写呢?

解决方案 »

  1.   

    问题补充 :加 images != null 
      

  2.   

    select * from tb1 where id=rand()
    union all
    select * from tb1 where id=rand()
    ...
      

  3.   

    rucypli , 这个 id=rand() 不管用耶... 
      

  4.   

    select * from (SELECT * from table1 ORDER BY RAND() LIMIT 1) a
    union all
    select * from (SELECT * from table2 ORDER BY RAND() LIMIT 1) b
     
    类似这样会好吗 ? 
      

  5.   

    select * from table1 where order by Rand()limit 1
    union all
    select * from table2 where order by rand() limit 1
    union all
    .....
      

  6.   

    (select * from table1 order by rand() limit 1 )
    union all
    (select * from table2 order by rand() limit 1 )
    union all
    (select * from table3 order by rand() limit 1 )
    union all
    (select * from table4 order by rand() limit 1 )
    union all
    (select * from table5 order by rand() limit 1 )
    union all
    (select * from table6 order by rand() limit 1 )
    union all
    (select * from table7 order by rand() limit 1 )
    union all
    (select * from table8 order by rand() limit 1 )
    union all
    (select * from table9 order by rand() limit 1 )
    union all
    (select * from table10 order by rand() limit 1) 
    union all
    (select * from table11 order by rand() limit 1) 
    union all
    (select * from table12 order by rand() limit 1) 
    union all
    (select * from table13 order by rand() limit 1) 
    union all
    (select * from table14 order by rand() limit 1) 
    union all
    (select * from table15 order by rand() limit 1)