Mysql Select Id in with And operator

283 views Asked by At

I want to get data from table where Id should be as given below in the query but instead of or I would apply and operator so lets say ID IN (5 AND 4 AND 3)

SELECT * FROM table WHERE id IN (5,4,3,1,6)

Is it possible to get data like this.

This is the sample query

SELECT PM.ContentID, PM.Author, PM.Title, PM.Journal, PM.Year, PM.Category, PM.StudyLocation, PM.FileURL from PublishedContentMaster PM join  TopicContentMapping T ON T.ContentID=PM.ContentID where PM.ContentID='100' AND T.TopicID IN (16,7) 

So I want which is present in both 16 and 17 that is why I need and operator not or.

1

There are 1 answers

0
Gordon Linoff On

I suspect that you want an aggregation query and a having clause. It would typically look something like this:

select x
from t
where id in (5, 4, 3, 1, 6)
group by x
having count(*) = 5;

In this case, x would be the column where you want five rows with the five values.