Search code examples
mysqlsymfonydqldoctrine-query

Query inside NOT IN statement Doctrine


I found this sentence in the code:

        $dql
            = <<<DQL
SELECT u FROM AppBundle:User u
JOIN u.Roles r
JOIN u.team t
WHERE u.id NOT IN (
      SELECT user.id
      FROM GameBundle:Goal g
      JOIN g.user user
      WHERE
        g.objective = :objective
    )
  AND 
    r.profile = :sales_profile
  AND 
    r.company = :company
  AND 
    u.onlyStatus NOT IN (:status)
DQL;

I don't know how to works that query inside NOT IN sentence, help me please.

I need to know:

  • What return the query inside of NOT IN, (data types, so on...)
  • How to works a query inside of NOT IN (is posible ?)

Solution

  • SELECT u FROM AppBundle:User u
    JOIN u.Roles r
    JOIN u.team t
    WHERE u.id NOT IN (
          SELECT user.id
          FROM GameBundle:Goal g
          JOIN g.user user
          WHERE
            g.objective = :objective
        )
    

    this means take all the users that don't currently have 'objective' in the 'Goal' table.

    Is this what you needed ?