sql - Return all rows from 2 tables and information from a 3rd -


I'm having trouble getting the desired results.

I have 3 tables: tbl_Policy 'a', Tbl_User 'b', tbl_ reviewed 'c'.

When a user reviews a policy, then current date (review date) in 'C' with UserAid and 'A' in policy 'C'.

EDIT: I need to see all the users, all the policies, and if they have been reviewed.

For this example: John has reviewed all 3 policies; James has reviewed only IT policy; January 2, 2014 John IT January 3, 2014 John Smoke 4 January 2014, 2014 James HR Neil James IT January 5, 2014 James Smith Nell Sara I can get all the user and all the policies with the following questions, but I am getting one for all 3 policies for each policy. Entry which poo Has been done ..

  choose a username, policy name, tbl_policy a, omitted from tbl_user b, omitted tbl_reviewed c ON.userid = b.userid  

Using the above example, this output:

  User policy date was reviewed by John HR January 2, 2014 John IT January 2, 2014 John Smoke January 2, 2014 John January 3, 2014 John IT January 3, 2014 John S. January 3, 2014 John HR January 4, 2014 John IT January 4, 2014 John Smoking January 4, 2014 James HR Jan January 2, 2014 James IT January 2, 2014 James Smith 2 January 2014 Sarah H. R. Nell Sarah IT Null All Sleeping Null I hope this is quite clear to give you an idea and Hope to help me in advance thanks.   

Do not mix different types of add-ons , Simply never does not use a comma there:

  select u.username, p.policyname, r.datereview from tbl_user u left tbl_reviewed r on u. Userid = RUsyrid Lift Job TBL Policy P.P. Yellowysis = rppolyside;  

It starts with tbl_user because you want to see all users, regardless of whether they have any reviewed policies or not.

I guessing in the event of joining policies.

Edit:

Now I think what you want to do. You want each policy for each user with one line and date:

  Select u.username, p.policyname, r.datereview from tbl_user and cross join tbl_policy p LEFT JOIN at tbl_reviewed r U.userid = r.userid and p.policyid = r.policyid command by user name, policy name;  

Comments