craygo Posted September 23, 2005 Share Posted September 23, 2005 I have two table called servpay, and roster. They are joined by the field playid, id respectively. I want to include all the people from the roster table in a report even if they have no entries in the servpay table. How would I do the JOIN for this??? Thanks Ray Quote Link to comment https://forums.phpfreaks.com/topic/2558-joins/ Share on other sites More sharing options...
imbrokn Posted September 23, 2005 Share Posted September 23, 2005 select from roster R LEFT JOIN servpay S on R.id = S.playID Quote Link to comment https://forums.phpfreaks.com/topic/2558-joins/#findComment-8491 Share on other sites More sharing options...
craygo Posted September 23, 2005 Author Share Posted September 23, 2005 is there a need to give the tables aliases?? this is what I have in my sql statement $qx = "SELECT roster.handle AS 'name', roster.real_name AS 'rname', "; $qx .= "EXTRACT(YEAR FROM servpay.paydate) AS 'YEAR', "; $qx .= "SUM(IF(servpay.paymonth = 1, servpay.amount, 0)) AS 'JANUARY', "; $qx .= "SUM(IF(servpay.paymonth = 2, servpay.amount, 0)) AS 'FEBRUARY', "; $qx .= "SUM(IF(servpay.paymonth = 3, servpay.amount, 0)) AS 'MARCH', "; $qx .= "SUM(IF(servpay.paymonth = 4, servpay.amount, 0)) AS 'APRIL', "; $qx .= "SUM(IF(servpay.paymonth = 5, servpay.amount, 0)) AS 'MAY', "; $qx .= "SUM(IF(servpay.paymonth = 6, servpay.amount, 0)) AS 'JUNE', "; $qx .= "SUM(IF(servpay.paymonth = 7, servpay.amount, 0)) AS 'JULY', "; $qx .= "SUM(IF(servpay.paymonth = 8, servpay.amount, 0)) AS 'AUGUST', "; $qx .= "SUM(IF(servpay.paymonth = 9, servpay.amount, 0)) AS 'SEPTEMBER', "; $qx .= "SUM(IF(servpay.paymonth = 10, servpay.amount, 0)) AS 'OCTOBER', "; $qx .= "SUM(IF(servpay.paymonth = 11, servpay.amount, 0)) AS 'NOVEMBER', "; $qx .= "SUM(IF(servpay.paymonth = 12, servpay.amount, 0)) AS 'DECEMBER' "; $qx .= "FROM roster LEFT JOIN servpay on roster.id=servpay.playid "; $qx .= "WHERE roster.title= 'OWNER' "; $qx .= "GROUP BY YEAR "; $qx .= "ORDER BY roster.id "; I have it being grouped by year but what happens when I insert a person for the year 2006 everyone's name goes away accept the one person that has paid for 2006. Quote Link to comment https://forums.phpfreaks.com/topic/2558-joins/#findComment-8492 Share on other sites More sharing options...
craygo Posted September 23, 2005 Author Share Posted September 23, 2005 Nobody cares LOL Quote Link to comment https://forums.phpfreaks.com/topic/2558-joins/#findComment-8494 Share on other sites More sharing options...
craygo Posted September 23, 2005 Author Share Posted September 23, 2005 I got it to work Thanks Quote Link to comment https://forums.phpfreaks.com/topic/2558-joins/#findComment-8495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.