Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL IN statement

Tags:

database

mysql

Im using IN to select stuff...

WHERE categories IN ("red", "blue", "green")

This selects any item in red, blue or green categories, my question is, is there a way to select an item that has to be in all three categories?

like image 974
panthro Avatar asked Jan 12 '12 15:01

panthro


People also ask

What is %s and %D in MySQL?

12 years, 11 months ago. it's for php to know how to handle the parameters, %d – the argument is treated as an integer, and presented as a (signed) decimal number. %s – the argument is treated as and presented as a string. in your examples, $slug is a string and $this->id is an integer.

Is there or in MySQL?

MySQL AND, OR and NOT Operators The AND and OR operators are used to filter records based on more than one condition: The AND operator displays a record if all the conditions separated by AND are TRUE. The OR operator displays a record if any of the conditions separated by OR is TRUE.

What does /* mean in MySQL?

The /* is the beginning of a comment and */ is the end of comment. Let us implement and display how to create a comment mysql> /* This is the first MySQL Program */ MySQL will ignore the above comment.

Can I use != In MySQL?

In MySQL, you can use the <> or != operators to test for inequality in a query. For example, we could test for inequality using the <> operator, as follows: SELECT * FROM contacts WHERE last_name <> 'Johnson';


1 Answers

SELECT Item
    FROM YourTable
    WHERE categories IN ('red', 'blue', 'green')
    GROUP BY Item
    HAVING COUNT(DISTINCT categories) = 3
like image 114
Joe Stefanelli Avatar answered Sep 19 '22 18:09

Joe Stefanelli