esport Posted April 8, 2008 Share Posted April 8, 2008 Hi guys, I have 2 tables 'tasks' and 'tasks_assigned_to'. I want to display all the tasks in the 'tasks' table'. easy select * from tasks however, when I join the 2 tables like SELECT * FROM tasks t LEFT JOIN tasks_asigned_to ta ON t.ID=ta.task_id It will only display the tasks that are in both tables. How do I display all tasks even if they aren't in the 'task_assigned_to' table. Thanks Daniel Link to comment https://forums.phpfreaks.com/topic/100236-solved-left-joins/ Share on other sites More sharing options...
aschk Posted April 9, 2008 Share Posted April 9, 2008 A LEFT JOIN IS the answer to your question, as it will SELECT everything that is in the left-hand table and JOIN it to the right-hand table EVEN if there is no information pertaining to a JOIN in the right hand table. (tasks is left-hand table, and tasks_assigned_to is right-hand table). A straight/inner JOIN will ONLY select data that corresponds in both tables. Link to comment https://forums.phpfreaks.com/topic/100236-solved-left-joins/#findComment-512751 Share on other sites More sharing options...
fenway Posted April 9, 2008 Share Posted April 9, 2008 That is, you should get all tasks regardless. Link to comment https://forums.phpfreaks.com/topic/100236-solved-left-joins/#findComment-512923 Share on other sites More sharing options...
esport Posted April 9, 2008 Author Share Posted April 9, 2008 I relised why it wont produce the results I want. I have a GROUP BY clause in the query grouping the taskid's in the task_assigned_to table so it wont produce duplicates. If so, how would I produce a result with all tasks without duplicates? SELECT * FROM tasks t LEFT JOIN tasks_asigned_to ta ON t.ID=ta.task_id GROUP BY ta.task_id Link to comment https://forums.phpfreaks.com/topic/100236-solved-left-joins/#findComment-513460 Share on other sites More sharing options...
esport Posted April 9, 2008 Author Share Posted April 9, 2008 ha i worked it out. i was grouping the wrong field. thanks for your help guys. Link to comment https://forums.phpfreaks.com/topic/100236-solved-left-joins/#findComment-513463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.