I have two tables i.e.
Invitation
- InvitationID
- UserID
Users
- UserID
- Username
I have data in both table
Invitation table data
29 NULL test1@example.com
40 8 test2@example.com
41 8 test3@example.com
Users table data
8 someone@example.com
Now I want to select all data from the Invitation table, and also want to select Username from Users table where Invitation.InvitationID is equal to Users.UserID.
I use this following query to select data
SELECT
Invitations.*, Users.UserName
FROM
Invitations
INNER JOIN
Users ON Invitations.UserID = Users.UserID
But it returns only two rows. I want to select all rows from the Invitation table. If Invitation.UserID is null then Username is also null. I want output like this:
29 NULL test1@example.com Null
40 8 test2@example.com someone@example.com
41 8 test3@example.com someone@example.com
You have to use left join :