Skip to content

Instantly share code, notes, and snippets.

@lunr
Created November 13, 2012 21:40
Show Gist options
  • Select an option

  • Save lunr/4068576 to your computer and use it in GitHub Desktop.

Select an option

Save lunr/4068576 to your computer and use it in GitHub Desktop.
Grade SQL Selection
$sql = "SELECT * FROM alpha WHERE letter REGEXP '%s' ORDER BY letter DESC;";
$letter = 'LL';
$regex = '^'.$letter.'$|^[A-'.(strlen($letter) > 1 ? substr($letter, -1) : chr(ord(substr($letter, -1)) - 1)).'].?$';
echo sprintf($sql, $regex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment