A Database Error Occurred

Error Number: 1064

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 'AND AwayTeam = ) OR ( AwayTeam = AND HomeTeam = )) AND `Played` = 1 ORDER BY `A' at line 4

SELECT GREATEST(HomeScore, AwayScore), MatchNo, HomeScore, AwayScore, HomeTeam, AwayTeam, matchstats.DivNo, matchstats.SsnNo, MatchDate, seasons.SsnName FROM (`football`.`matchstats`) JOIN `football`.`seasons` ON `seasons`.`SsnNo` = `matchstats`.`SsnNo` WHERE ((HomeTeam = AND AwayTeam = ) OR ( AwayTeam = AND HomeTeam = )) AND `Played` = 1 ORDER BY `AwayScore` desc LIMIT 1

Filename: G:\footymad\www.footymad.net\system\database\DB_driver.php

Line Number: 328