Skip to content

Instantly share code, notes, and snippets.

@PierreLebedel
Last active June 28, 2017 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierreLebedel/09ab7545d63b6db8e7db974a3de94d7f to your computer and use it in GitHub Desktop.
Save PierreLebedel/09ab7545d63b6db8e7db974a3de94d7f to your computer and use it in GitHub Desktop.
MySQL select rows where field contains X occurences
SELECT id, ROUND(
( LENGTH(field) - LENGTH( REPLACE(field, "search", "") ) ) / LENGTH("search")
) AS count
FROM table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment