当前位置: 代码迷 >> Java Web开发 >> 多表牧户查询sql语句如何写?查出来有如何显示在页面中
  详细解决方案

多表牧户查询sql语句如何写?查出来有如何显示在页面中

热度:5068   发布时间:2013-02-25 21:06:00.0
多表牧户查询sql语句怎么写?查出来有怎么显示在页面中
商品表1:table1(id,name,price)
商品表2:table(id,name,price)
需求是找出表一和表二中的最贵的5件商品,并显示在页面中,该怎么做,求指教啊!
查出来后返回值是什么类型啊?
因为一会是表一的数据类型,一会是表二的数据类型啊?
先Union,再查,大致是:
Select id, name, price
From (
    Select * From table1
    Union
    Select * From table2

Order By price Desc
Where rownum <= 5


性能改进是:
Select id, name, price
From (
    Select * From table1 Order By price Desc Where rownum <= 5
    Union
    Select * From table2 Order By price Desc Where rownum <= 5

Order By price Desc
Where rownum <= 5
  相关解决方案