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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.