|
SQL LEFT Join keyword will returns all records from the left table, even if there are no matches in the right table.
Table Name ‘Users’
|
U_Id
|
FirstName
|
LastName
|
City
|
|
1
|
Ajay
|
senha
|
New York
|
|
2
|
Vinda
|
kapoor
|
Los Angeles
|
|
3
|
Qasim
|
bilal
|
New York
|
In this table U_Id is primary key.
Table Name ‘UserCourses’
|
Uc_id
|
CourseNo
|
U_Id
|
|
1
|
34190
|
1
|
|
2
|
34192
|
1
|
|
3
|
34190
|
|
SELECT Users.U_Id, Users.FirstName, Users.LastName, UserCourses.CourseNo
FROM Users
LEFT JOIN UserCourses
ON Users.U_Id=UserCourses.U_Id
Order By Users.U_Id
|
U_Id
|
FirstName
|
LastName
|
CourseNo
|
|
1
|
Ajay
|
senha
|
34190
|
|
1
|
Ajay
|
senha
|
34192
|
|
2
|
Vinda
|
kapoor
|
34190
|
|
3
|
Qasim
|
bilal
|
|
|