4

I'm new to MySQL and still have issues with its syntax. I have this query:

SELECT a, b, c, d, e
FROM table1
WHERE status = 'skipped' 
AND batchid IN (SELECT batchid 
                FROM (SELECT distinct batchid, date_format(uploaddate, '%Y-%m-%d') 
                      FROM table1 
                      WHERE uploaddate > '2011-01-26') AS t
               ) AS t;

which gives me this error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as t' at line 1

The IN clause works:

SELECT batchid 
FROM (SELECT distinct batchid, date_format(uploaddate, '%Y-%m-%d') 
      FROM table1 
      WHERE uploaddate > '2011-01-26') AS t

I think my issue has something to do with the second table alias. Can somebody show me what I'm doing wrong?

Tim Martin
  • 3,618
  • 6
  • 32
  • 43
sdoca
  • 7,832
  • 23
  • 70
  • 127

1 Answers1

4

You don't need an alias for subqueries appearing in the WHERE clause.

Leave off the final AS t (just before the semicolon) and all should be well.

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223