0

keep getting error when it try to select 4 random rows. not sure i got the snytax right for doing this. Also note i am using an access db. Also note.. ManaTypes is an array of strings.

with adoquery1 do
begin
  close;
  sql.Clear;
  sql.Add('SELECT * ');
  sql.Add('FROM Cards ');
  sql.Add('WHERE Color='+ManaTypes[i]+' ORDER BY RAND() Limit 4');
  open;
end;

Getting error 'snytax error (missing operator ) in query expression 'Color="

kobik
  • 21,001
  • 4
  • 61
  • 121
Glen Morse
  • 2,437
  • 8
  • 51
  • 102

1 Answers1

2

Try

sql.Add(
   'SELECT Top 4 *
    FROM
    (
       SELECT *, Rnd(ID) AS RandomValue
       FROM Cards 
       WHERE Color = "' + ManaTypes[i] + '"
    )
    ORDER  BY RandomValue'
juergen d
  • 201,996
  • 37
  • 293
  • 362