I have this tables in my DB:
“USERS”
id email name last_access
1 user1@gmail.com Name1 Surname1 2012-10-05 13:58:19.0
2 user2@gmail.com Name2 Surname2 2012-10-05 13:56:59.0
3 user3@gmail.com Name3 Surname3 2012-10-05 13:57:57.0
“NETS_PERMISSIONS”
user_id network_id perm
1 1234 3
2 1235 3
Now, I have this query:
SELECT DISTINCT user.id, user.name, nets.network_id, nets.perm
FROM users as user LEFT OUTER JOIN nets_permissions AS nets
ON user.id = nets.user_id AND nets.perm <> 3 WHERE user.id!=1 AND nets.network_id=1234
The result query is empty, but instead I want that
– from the ‘nets_permissions’ table, are left out rows with perm=3 and user_id and network_id like spiecified in the query (in this case for ex. user_id=1 and network_id=1234): in this case the left part of the query is empty.
– from the ‘users’ table I want take every row but, if it isn’t in the ‘nets_permissions’ table, the rows have network_id and perm .
So, from this two tables, in this example, I would this result:
id name network_id perm
2 Irene Pippo <null> <null>
3 Luca Niccolini <null> <null>
Thank you very much to all of you for your help.
This should give you what you want–only users who don’t have perm 3 and nework_id 1234