Re: [SQL ] 請問從五個資料表內抓最新的五筆SQL怎麼下

看板Database作者 (Lvx ex Caelis)時間18年前 (2007/11/04 08:17), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串7/7 (看更多)
前面五張表格,所以用 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
文章代碼(AID): #17BG-Fzt (Database)
討論串 (同標題文章)
文章代碼(AID): #17BG-Fzt (Database)