开发者

MySQL single row with multiple records

开发者 https://www.devze.com 2023-03-10 22:53 出处:网络
I have a table with contains multiple rows that define \"amenities\" for a particular resort. I need to return the resortID if there are rows containing whatever \"amenOptionID\" I define. My issue co

I have a table with contains multiple rows that define "amenities" for a particular resort. I need to return the resortID if there are rows containing whatever "amenOptionID" I define. My issue comes in where I'm lookin开发者_运维知识库g to see if a resort has two or more amenities. For example:

I want to return resortIDs that have BOTH amenOptionID 1 AND 4. I also do not want duplicate resortIDs. Refer to the image for the table structure. Thanks in advance for any help.

MySQL single row with multiple records


  SELECT `resortID`
   WHERE `amenOptionID`
         IN (1, 4) 
GROUP BY `resortID`
  HAVING COUNT(*) = 2


I think this will work...

SELECT resortID, COUNT(*) AS theCount FROM myTable WHERE amenOptionID IN(1,4) GROUP BY resortId HAVING theCount=2;
0

精彩评论

暂无评论...
验证码 换一张
取 消