作者bcse (Lvx ex Caelis)
看板Database
标题Re: [SQL ] 请问从五个资料表内抓最新的五笔SQL怎麽下
时间Sun Nov 4 08:17:18 2007
前面五张表格,所以用 subquery 就算了
这只有一张表格用什麽 subquery...
SELECT *
FROM boards
WHERE board_name IN (1,2,3,4,5)
ORDER BY posttime
LIMIT 5
资料库系统不支援 IN 的话,可以换成
WHERE board_name = 1 OR board_name = 2 OR ...
※ 引述《gargamel (Nerding)》之铭言:
: 抄的...XD
: select * from (
: (select * from boards
: where board_name = '1'
: order by posttime limit 5) union
: (select * from boards
: where board_name = '2'
: order by posttime limit 5) union
: (select * from boards
: where board_name = '3'
: order by posttime limit 5) union
: (select * from boards
: where board_name = '4'
: order by posttime limit 5) union
: (select * from boards
: where board_name = '5'
: order by posttime limit 5))
: order by posttime limit 5;
: 这样?
: ※ 引述《pakker (找寻蔚蓝天空)》之铭言:
: : select * from (
: : (select * from board1 order by posttime limit 5) union
: : (select * from board2 order by posttime limit 5) union
: : (select * from board3 order by posttime limit 5) union
: : (select * from board4 order by posttime limit 5) union
: : (select * from board5 order by posttime limit 5) union
: : ) AS U order by posttime limit 5;
: : 这样?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 134.208.33.185