I have two tables member
and alumni
. alumni
table can have the same member
in more than one row with a different year
field. I want to select all the data from both the table.
The table given is:
Alumni:
id, regd, name, status, year
1 1 kim inactive 2013
2 1 kim inactive 2014
3 1 kim inactive 2015 //This is generated for alumni purpose
The table member given is:
regd, name, status, year
1 kim Active 2015
The expected output is:
`regd`, `name,` `status,` `year`
1 kim Active 2015
1 kim inactive 2014
1 kim inactive 2013
If there is no record of for example 2015 year in alumni
, it will still display the other record in alumni
and 2015 from member
table. I am trying to display this with regd
using the following php and mysql statement but it does not work as expected.
Mysql:
SELECT m.*, a.* FROM member m
LEFT JOIN alumni a ON m.regd = a.regd
WHERE m.regd ='1' GROUP BY a.year ORDER BY a.year DESC;
PHP:
foreach($members as member):
echo $member['regd'].' '.$member['year'].'<br>';
endforeach;
The error is, it selects all data from alumni
table only. Where could I go wrong? Though I did not provide fiddle here, I hope this makes my point clear. please help me.