I have two tables and want to join the result from these two tables but my condition here is:
Member Table +------+----------+--------+----------------------+ | a_id | name | Active | Date | +------+----------+--------+----------------------+ | 1 | Da Vinci | 1 | 2012-03-27 15:40:14 | | 2 | Monet | 0 | 2012-04-16 01:14:17 | | 3 | Van Gogh | 0 | 2012-03-22 15:49:59 | | 4 | Picasso | 1 | 2012-02-27 09:40:05 | | 5 | Renoir | 1 | 2012-04-22 15:40:14 | +------+----------+--------+----------------------+ Purchase Table +------+------+-------------------+---------------------+-------+ | a_id | p_id | title | purchase date | price | +------+------+-------------------+---------------------+-------+ | 1 | 1 | The Last Supper | 2012-03-27 15:40:14 | 34 | | 1 | 2 | The Mona Lisa | 2012-04-27 15:40:14 | 87 | | 3 | 3 | Starry Night | 2012-03-27 15:40:14 | 48 | | 3 | 4 | The Potato Eaters | 2012-03-27 15:40:14 | 67 | | 3 | 5 | The Rocks | 2012-03-27 15:40:14 | 33 | | 5 | 6 | Les Deux Soeurs | 2012-04-30 15:40:14 | 64 | +------+------+-------------------+---------------------+-------+
From the tables above I want to find the 2 most recent active members (member table) and their last 1 purchase made from purchase table. Its result should looks like:
+------+------+-------------------+---------------------+-------+ | a_id | p_id | title | purchase date | price | +------+------+-------------------+---------------------+-------+ | 1 | 2 | The Mona Lisa | 2012-04-27 15:40:14 | 87 | | 5 | 6 | Les Deux Soeurs | 2012-04-30 15:40:14 | 64 | +------+------+-------------------+---------------------+-------+
I have tried hours to find the answer to this question but have not found any solution. Please help me.
Thank you for your support.