WordPress: Using the category slug get the category ID using mysql query

Instead of writing custom SQL, you should be able to just use the native get_category_by_slug() which will return a full category object to include the category ID.