This is a question for learning sense more than I need to find a solution. I have a product entity, and it has an attribute of product_name. I would like to search product_name and return all products that have more than 1 'a' in the product_name. I need help with the query for this.
This code shows all products that have 'a'
SELECT product_name AS 'Product Names' FROM product WHERE name LIKE '%a%'
BUT I'm after products that have more than 1 'a'. Structure: Product
Product(p_Id, product_name, p_cost)
So if I had a product called "Car Manual" it would return as there are 3 'a's. Please help.
The query would look like:
SELECT product_name AS ProductNames
FROM product
WHERE name LIKE '%a%a%';
Don't use single quotes for column aliases. The best thing to do is to name the columns so they don't need to be escaped. Otherwise use backticks, double quotes, or square braces, depending on your database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With