Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use two where clauses, like "SELECT * FROM table WHERE something and something"?

Tags:

sql

php

mysql

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!

like image 994
KeriLynn Avatar asked May 02 '10 17:05

KeriLynn


People also ask

Can you use WHERE clause twice in SQL?

But yes, you can use two WHERE.

Can we use two WHERE clause in MySQL?

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.

Can we use both WHERE and HAVING in one SELECT statement?

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.

WHERE and HAVING clauses Cannot be used in the same SELECT statement?

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.


1 Answers

$query = "SELECT * FROM products WHERE products.colors LIKE '%black%' AND products.category = 'bracelet'";

There you go.

like image 188
Conspicuous Compiler Avatar answered Sep 22 '22 06:09

Conspicuous Compiler