I have to deal with already developed system where we have users that are set into a mysql table users. There is a second table called users_preferences. That table stores user privacy settings. It’s all ok except for that it is not necessary to have a record for every user. If there is no record, i have to assume that the user is public. This is where the problem is – i’m trying to search in the users table, based on the users_preferences table. What I have so far is:
SELECT users.id AS id, users.username AS username, users.avatar AS avatar, IF(users_preferences.privacyControls is null OR users_preferences.privacy = 0), 0, 1) AS userPrivacy
FROM users, users_preferences
WHERE users_preferences.userid = users.id AND userPrivacy = 0 AND users.username LIKE '%demo_user%'
That query is not valid and throws an error, but it will give you a basic idea what i want to do – I want to select those users that have set users_preferences.privacy = 0 (OR there is no such record).
Thanks in advance.
1 Answer