select userid,username,price,vol from table_a ...
select userid,username,price,vol from table_b...
要让这两句形成一个结果集。怎么办?

解决方案 »

  1.   

    select userid,username,price,vol from table_a ...
    union all
    select userid,username,price,vol from table_b...
      

  2.   


    select userid,username,price,vol from table_a ...
    union all--不去掉上下两语句的重复行
    select userid,username,price,vol from table_b...
    select userid,username,price,vol from table_a ...
    union--去掉上下两语句的重复行
    select userid,username,price,vol from table_b...
      

  3.   

    select userid,username,price,vol from table_a ...
    union all
    select userid,username,price,vol from table_b...
     
      

  4.   


    就是你上面那个语句和下面那个语句的结果中如果有数据是一模一样的行的话就只显示一行。
    只能在下面那个查询语句后面跟order by
    select userid,username,price,vol from table_a ...
    union all
    select userid,username,price,vol from table_b...order by ....也可以select * from(
    select userid,username,price,vol from table_a ...
    union all
    select userid,username,price,vol from table_b...
    )t order by ....