Попробуйте, просто не спрашивайте:)
select
left(substring(post_content,locate('[nggallery id=',post_content)+14,5),locate(']',substring(post_content,locate('[nggallery id=',post_content)+14,5))-1) as NumValue, post_content
from wp_posts
WHERE post_content LIKE "[nggallery id=%]"
ORDER BY 1