尝试按限制降序排序时出现语法错误

I am using the following code:

//Get latest version of regulation related to this CE Group
$rstmp = CustomQuery("
SELECT * 
  FROM EURegulations 
 ORDER 
    BY ValidFrom DESC 
 LIMIT 1 
 where CEGroupFk='".$values['CEGroupFk']."'
");
$datatmp = db_fetch_array($rstmp);

The purpose is to return the latest item in that list that is relevant to that foreign key.

I am getting the following message:

  1. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where CEGroupFk='5'' at line 1;
  2. 256;

The array seems to returning good data:

  1. Array ( [EURegulationReference] => test [EURegulationTitle] => test [ValidFrom] => 2019-06-19 00:00:00 [ValidTo] => 2019-06-28 00:00:00 [Attachment] => [CEGroupFk] => 5 [E...;
  2. Array ( [EURegulationPk] => 2 ) ;

I am assuming that there is a problem with my customquery code but cannot see it?

The order by clause must be placed after the where clause

$rstmp = CustomQuery("
  SELECT * FROM EURegulations 
   where CEGroupFk='".$values['CEGroupFk']."'
   ORDER BY ValidFrom DESC LIMIT 1
   ");