我有以下MySQL查詢:有沒有辦法從每個查詢中獲取2行?
SELECT m.id AS id, 'admin' AS type, m.title AS title, m.message AS message, m.link AS link, m.image AS image, 'White' AS colour_scheme
FROM x_elder_messages m
UNION
SELECT a.id AS id, 'evidence' AS type, a.name AS title, a.about AS message, CONCAT('http://www.aaa.com/x/view/ambition/',a.id,'/') AS link, CONCAT('http://www.aaa.com/x/x_images/x_ambitions/current/thumb/',ai.image_id,'.jpg') AS image, 'White' AS colour_scheme
FROM x_ambitions a
INNER JOIN x_ambition_images ai
ON a.id = ai.ambition_id
UNION
SELECT u.id AS id, 'profile_update' AS type, CONCAT(u.x_first_name,' ',u.x_last_name) AS title, CONCAT(CONCAT(u.x_first_name,' ',u.x_last_name),' has recently updated their profile') AS message, CONCAT('http://www.aaa.com/x/view/',u.id,'/') AS link, CONCAT('http://www.aaa.com/x/x_images/x_users/current/thumb/',i.image_id,'.jpg') AS image, 'Dark' AS colour_scheme
FROM x_user u
INNER JOIN x_user_images i
ON u.id = i.user_id
ORDER BY RAND()
我有輸出有相同的列名,這樣我可以處理結果作爲一個整體。但有沒有辦法限制每個查詢2,所以它會搶2管理員,2個野心,2用戶?
感謝
感謝您的快速響應,有沒有什麼辦法,隨機洗牌查詢的整個輸出?我只是簡單地把一個ORDER BY RAND()放在最後? – cwiggo
是的,它的作品,塔! :) – cwiggo