SQL error in QUERY: SELECT t.type, COUNT(*) FROM threads t JOIN ( SELECT DISTINCT t.uid FROM threads t JOIN thread_stops ts ON ts.thread_uid = t.uid JOIN stations s ON s.station_id = ts.station_id AND t.station_start <> s.station_id AND t.station_end <> s.station_id WHERE s.city_id = 213 ) a ON a.uid = t.uid GROUP BY t.type Array ( [0] => HY000 [1] => 1030 [2] => Got error 28 from storage engine )