
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.96 KB | hits: 12 | expires: Never
Using limit clause along with union all or selecting top 2 and last 3 results
select *
from tbl_product asc
union
select *
from tbl_product desc
order by pd_price limit 2
SELECT * FROM (
SELECT *
FROM tbl_product
ORDER BY pd_price ASC
LIMIT 2
) tbl1
UNION ALL
SELECT * FROM (
SELECT * FROM (
SELECT *
FROM tbl_product
ORDER BY pd_price DESC
LIMIT 3
) tbl_a
ORDER BY pd_price ASC
) tbl2
select *
from (
SELECT *
FROM `tbl_product`
order by pd_price desc limit 2
) as t1
union all
select *
from (
SELECT *
FROM `tbl_product`
order by pd_price asc limit 3
) as t2
CREATE TEMPORARY TABLE IF NOT EXISTS `tmp_table` ENGINE=MEMORY SELECT `field` FROM `tbl` ORDER BY `id` ASC LIMIT 2;
INSERT INTO tmp_table SELECT `field` FROM `tbl` ORDER BY `id` DESC LIMIT 3;
SELECT field FROM tmp_table;