I would like to receive all users that does not contain the hobby reading. So basically query_2 should be subtracted with query_1 that I obtain all users without the reading value.
query_1: SELECT fk_user FROM table1 WHERE hobby = ‘cooking’;
query_2: SELECT DISTINCT fk_user FROM table1;
Unless I’m missing something all you need is:
SELECT DISTINCT fk_user FROM table1 WHERE hobby = 'cooking' AND hobby != 'reading' ;
Failing to see why you need a second query here.
You can use aggregation to sum the occurrences of the hobby being
'reading' and filter on them being
0. Same goes analog for
SELECT fk_user FROM table1 GROUP BY fk_user HAVING sum(hobby = 'reading') = 0 AND sum(hobby = 'cooking') > 0;
There are many approaches to achive that. My proposition would be:
SELECT DISTINCT fk_user FROM table1 WHERE hobby IS NOT NULL AND hobby != 'reading' AND hobby = 'cooking';