I need to get top 2 records of each id from table:
SELECT distinct table1.userid AS `Foruser`,
(Select table2.Firstname from table2
where table2.table2id = table1.userid ) as 'USERName',
(Select table2.email from table2
where table2.table2id = table1.userid ) as 'USERMail',
(Select table2.gender from table2
where table2.table2id = table1.userid ) as 'USERGender',
table2.table2id as 'MatchProfileID',
table2.Firstname,
table2.LastName,
table2.age,
table2.gender
FROM database.table2 table2, database.table1 table1
WHERE (table2.age BETWEEN table1.minage AND table1.maxage)
AND (table2.gender = table1.Gender)
order by table1.userid