I have a table with my products and I'm trying to write a page that would pull bracelets with certain colors from the database. So here's what I have right now (in php):
$query = "SELECT * FROM products WHERE (products.colors LIKE '%black%')";
But I only want to select rows where the value for the column "category" equals "bracelet".
I've tried a few different things, but I keep getting warnings and errors. I appreciate any help you can give, thank you!
But yes, you can use two WHERE.
MySQL allows you to specify multiple WHERE clauses. These clauses may be used in two ways: as AND clauses or as OR clauses. What is Operator? An operator is a special keyword used to join or change clauses within a WHERE clause.
You can create a WHERE clause and HAVING clause involving the same column. To do so, you must add the column twice to the Criteria pane, then specify one instance as part of the HAVING clause and the other instance as part of the WHERE clause.
We cannot use the HAVING clause without SELECT statement whereas the WHERE clause can be used with SELECT, UPDATE, DELETE, etc. WE can use aggregate functions like sum, min, max, avg, etc with the HAVING clause but they can never be used with WHERE clause. HAVING clause is generally used with the GROUP BY.
$query = "SELECT * FROM products WHERE products.colors LIKE '%black%' AND products.category = 'bracelet'";
There you go.
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