日期:2014-05-17  浏览次数:20631 次

多表牧户查询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