Reputation: 7589
i'm having the following tables:
USERS: ITEMS
user_id name always_show id user_id name
-------------------------- --------------------------------
1 Joe 1 1 Apple
2 Sam 2 1 Banana
3 Walter 1 3 2 Cherry
i'm doing this query:
SELECT * FROM
users Inner Join
items On users.user_id = items.user_id
The question is: how can i add all other users which have the flag always_show set?
Upvotes: 0
Views: 57
Reputation: 8709
SELECT *
FROM users
INNER JOIN items On users.user_id = items.user_id
UNION
SELECT *
FROM users
LEFT OUTER JOIN items On users.user_id = items.user_id AND users.always_show = 1
Upvotes: 0
Reputation: 7887
i hope i understand your question :-) try UNION
SELECT u.* FROM users u
INNER JOIN items i ON u.user_id = i.user_id
UNION ALL SELECT * FROM users WHERE always_show = 1
Upvotes: 1
Reputation: 53
SELECT * FROM
users Inner Join
items On users.user_id = items.user_id where Users.always_set = 1
Upvotes: 0