Syntax error with “Rand()” function in MySQL in Delphi
问题 I am trying to use the Rand() function within MySQL to select a random record but I am getting a syntax error in the Rand() LIMIT line qryCards.SQL.Add('SELECT * FROM tblCards WHERE Card_Rarity = "Epic"'); qryCards.Open; iCount := qryCards.RecordCount; qryCards.Close; qryCards.SQL.Clear; qryCards.SQL.Add('SELECT * FROM tblCards ORDER BY rand(' + IntToStr(iCount) + ') LIMIT 1'); qryCards.Open; ShowMessage(qryCards.FieldByName('Card_Name').AsString); 回答1: First off, you are not using RAND()