SQL: Output all names which belong to a category where all the countries within it are the same

前端 未结 3 1137
难免孤独
难免孤独 2021-01-28 06:59

I have the following table called Stores:

Name          |   Country   |   Category 
Pharmacy          Japan         Health
Green Vine        Italy         Dining         


        
3条回答
  •  天涯浪人
    2021-01-28 07:23

    You can use EXISTS :

    SELECT t.*
    FROM table t
    WHERE EXISTS (SELECT 1 
                  FROM table t1 
                  WHERE t1.Country = t.Country AND 
                        t1.category = t.category AND
                        t1.Name <> t.Name
                 );
    

提交回复
热议问题