views:

33

answers:

2

Hi,

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

+3  A: 

/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
OMG Ponies
Hi OMG Ponies, That worked great. Thanks. I've got read up on CASE and WHEN as they are beyond my 'SELECT *' level skills. Again, thanks.
Laxmidi
+1  A: 

Error in sub-query - alias t is not defined here

          (SELECT *, 
          CASE t.type
            WHEN 'Advanced' THEN t.type
            ELSE 'Non-Advanced'
          END AS group_type
          FROM tester)x .... 
a1ex07
+1: It was my copy'n'paste error that's to blame :(
OMG Ponies