Search code examples
sqlmysqlmysql-error-1054

MySQL unknown column


Why am I getting this error:

1054 - Unknown column 't.type' in 'field list'

I have a column called type in my table. And I've got the table 'tester' using an alias t.

SELECT y.*,
           (SELECT COUNT(*)
              FROM (SELECT *, 
                           CASE t.type
                             WHEN 'Advanced' THEN t.type
                             ELSE 'Non-Advanced'
                           END AS group_type
                      FROM tester) x
             WHERE x.group_type = y.group_type
               AND (x.grade1 + x.grade2) >= (y.grade1 + y.grade2)) AS rank
      FROM (SELECT t.name,
                   t.grade1,
                   t.grade2,
                   t.type,
                   CASE t.type
                     WHEN 'Advanced' THEN t.type
                     ELSE 'Non-Advanced'
                   END AS group_type
              FROM tester t) y

OMGPonies, any ideas?

Thank you.

-Laxmidi


Solution

  • /me smacks my forehead - my fault, sorry.

    Use this:

    SELECT y.*,
           (SELECT COUNT(*)
              FROM (SELECT *, 
                           CASE type
                             WHEN 'Advanced' THEN type
                             ELSE 'Non-Advanced'
                           END AS group_type
                      FROM tester) x
             WHERE x.group_type = y.group_type
               AND (x.grade1 + x.grade2) >= (y.grade1 + y.grade2)) AS rank
      FROM (SELECT t.name,
                   t.grade1,
                   t.grade2,
                   t.type,
                   CASE t.type
                     WHEN 'Advanced' THEN t.type
                     ELSE 'Non-Advanced'
                   END AS group_type
              FROM tester t) y