* Henning Sprang
> Now I want to create a query to get all task_id's which one given User
> isn't already assigned to. I tried a lot of things, Joined in every
> direction and so but do not come to my result.

The problem in this situation is that you want to join with records that are
not there. I suppose you have no problem selecting the Tasks that _are_
assigned to a User.

To find the non-existing records, you need to use LEFT JOIN. You use it like
a normal JOIN, but a LEFT JOIN returns a row even if the associated record
is not found, and fills all fields from that record with NULL. Because the
non-existing records are what you want in this case, you add a
ISNULL(Auth.user_id) to your WHERE clause:

SELECT Task.task_id
  FROM Task,User
  LEFT JOIN Auth ON
    Auth.user_id=User.user_id AND
    Auth.task_id=Task.task_id
  WHERE
    ISNULL(Auth.user_id) AND
    User.username="roger";

--
Roger


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to