title: "Every derived table must have its own alias" in complex MySQL query
body: <p>I have a more or less complex MySQL select query which is basically a select from a join of two complex tables:</p>
  
  <pre><code> SELECT * 
    FROM 
       ( SELECT ProblemID
              , 10*POWER(COUNT(ProblemID), 2) AS TagsSignifikanz 
           FROM 
              ( SELECT ProblemID 
                  FROM Problemtag 
                 WHERE Tagtext = "Francois" 
                 UNION 
                   ALL 
                SELECT ProblemID 
                  FROM Problemtag 
                 WHERE Tagtext = "Hollande"
              ) AS TagsSignifikanzTable 
          GROUP 
             BY ProblemID
       ) 
    JOIN 
       ( SELECT ProblemID
              , SUM(Einzelsignifikanz) AS Titelsignifikanz 
           FROM 
              ( SELECT ProblemID
                     , 1 AS Einzelsignifikanz 
                  FROM Problem 
                 WHERE Titel LIKE "%Francois%" 
                 UNION 
                   ALL 
                SELECT ProblemID
                     , 1 AS Einzelsignifikanz 
                  FROM Problem 
                 WHERE Titel 
                  LIKE "%Hollande%" 
                 UNION 
                   ALL 
                SELECT ProblemID
                     , 4 AS Einzelsignifikanz 
                  FROM Problem 
                 WHERE Titel LIKE "%Francois Hollande%"
              ) AS TitelSignifikanzTable 
          GROUP 
             BY ProblemID
        ) AS TagsUndTitelSignifikanzTable 
       ON TagsSignifikanzQuery.ProblemID = TitelsignifikanzQuery.ProblemID;
  </code></pre>
  
  <p>I have been trying around for a while, but just can't figure out where I should insert a derived table's name. Who can help me out? Thanks in advance!</p>
  
  <p>EDIT - The solution, by help of BK435 and Drew: (see line 7 and last 2 lines)</p>
  
  <pre><code>SELECT * FROM (
      SELECT ProblemID, 10*POWER(COUNT(ProblemID), 2) AS TagsSignifikanz FROM (
          SELECT ProblemID FROM Problemtag WHERE Tagtext = "Francois" 
              UNION ALL 
          SELECT ProblemID FROM Problemtag WHERE Tagtext = "Hollande"
      ) AS TagsSignifikanzTable GROUP BY ProblemID
  ) As Alias1
  JOIN (
      SELECT ProblemID, SUM(Einzelsignifikanz) AS Titelsignifikanz FROM (
          SELECT ProblemID, 1 AS Einzelsignifikanz FROM Problem WHERE Titel LIKE "%Francois%" 
              UNION ALL 
          SELECT ProblemID, 1 AS Einzelsignifikanz FROM Problem WHERE Titel LIKE "%Hollande%" 
              UNION ALL 
          SELECT ProblemID, 4 AS Einzelsignifikanz FROM Problem WHERE Titel LIKE "%Francois Hollande%"
      ) AS TitelSignifikanzTable GROUP BY ProblemID
  ) AS Alias2 
  ON Alias1.ProblemID = Alias2.ProblemID;
  </code></pre>