I have a simple module base settings tables in database as below :
Module1
UserId | Active // other columns
*00000000-0000-0000-0000-000000000AB1* | *True*
Module2
UserId | Active // other columns
*00000000-0000-0000-0000-000000000AB1* | *False*
Module3
UserId | Active // other columns
*00000000-0000-0000-0000-000000000AB1* | *True*
I want to select if modules are active or not for specific user and output result something like this
Module1 | Module2 | Module3
True | False | True
I have tried this query using Join
:
SELECT Module1 = module1.Active, Module2 = module2.Active, Module3 = module3.Active
FROM [dbo].[Module1] AS module1 JOIN
[dbo].[Module2] AS module2 ON module1.UserId = module2.UserId JOIN
[dbo].[Module3] AS module3 ON module2.UserId = module3.UserId JOIN
WHERE module1.UserId = '00000000-0000-0000-0000-000000000AB1'
that gives me the exact output what I required. But if there is not a matching row for that user in any of the table, then all columns will be empty in result set.
How should I update my query to handle if any table has not a matching record so that value for that table's column be null or default value in result set.
Edit : datatype of UserId is uniqueidentifier and for Active is bit.