Mysql

查詢錯誤 int/varchar LEFTJOIN

  • March 2, 2015

有人能告訴我這個查詢有什麼問題嗎?

$sql = "select 
bans.id as banid,
bans.type,
bans.data,
bans.reason,
bans.expire,
bans.added_by,
bans.added_date,
players.id as playerid,
players.username,
FROM bans 
LEFT JOIN players
ON cast(players.id as varchar(50)) = bans.added_by                       
WHERE `bans.id` LIKE '%".$amount."%' OR 
`bans.added_by` LIKE '%".$amount."%' OR 
`bans.data` LIKE '%".$amount."%' OR 
`players.username` LIKE '%".$amount."%' OR 
`bans.data` LIKE '%".$usernamevanamount."%' OR 
`bans.reason` LIKE '%".$amount."%' 
ORDER BY bans.added_date DESC"; 
$result = mysql_query($sql) or die('Error, insert query failed with:' . mysql_error());`

players.id = int

bans.added_by = varchar(50)

錯誤:

您的 SQL 語法有錯誤;檢查與您的 MariaDB 伺服器版本相對應的手冊,以在第 11 行的“FROM bans LEFT JOIN player ON cast(players.id as varchar(50)) = bans. added_by 附近使用正確的語法

取出 FROM: 之前的逗號字元player.username, FROM bans

引用自:https://dba.stackexchange.com/questions/94195