Reputation: 2774
Is it possible to return all rows based in condition? Example:
SELECT
*
FROM
TABLE
WHERE
USER IN ('A', 'B', 'C')
In the example above it will return only if there is a user A, B and C. If The user C doesn't exist it will return only 2 rows, A and B. I would like to have 3 rows, and the C with empty.
Thanks.
Upvotes: 1
Views: 42
Reputation: 1185
You can take advantage of LEFT join here..
WITH cte AS
(SELECT 'a' AS user UNION ALL
SELECT 'b'
SELECT 'c'
)
SELECT * FROM cte
LEFT JOIN tablename ON yourcolumnName = user
Upvotes: 2
Reputation: 5442
You could use this
SELECT
t1.[user],
t.*
FROM
(
SELECT 'A' [user]
UNION ALL
SELECT 'B'
UNION ALL
SELECT 'C'
) t1
LEFT JOIN
table_name t
ON t.[user] = t1.[user];
Upvotes: 1