I want to get 5 emails of every account of Inbox
folder from "Mails" Table
Table contain field of MailAccountID.
Table details:
Table Name: Mails
Folder field: FolderName
Email Account field: MailAccountID
I have tried solution suggested. It works fine If I execute query in MySQL query window but it throw so many errors as Stored Procedure.
Stored Procedure:
CREATE PROCEDURE `SP_GetMailAccountData`()
BEGIN
select * from
(
select m.*,
if(m.mailaccountid <> @prev ,@rn:=1,@rn:=@rn+1) rn,
@prev:=m.mailaccountid prev
from (select @rn:=0,@prev:='') p, mails m
where foldername = 'inbox'
order by m.mailaccountid,m.dt desc
) s
where s.rn <= 3;
END