sql - how to make a column's value match all the values from a subquery -


how column's values match values subquery?

here table :

table p p# - pname - color - city 1  -  nut  -  red  - london 2  -  bolt - green - paris 3  - screw - blue  - rome 4  - cam   - blue  - paris ... 

for example, if want name of cities have same color of piece (p)?

i thinking query:

select city p city = 'blue'; 

of course, it's cheating because have few rows, how write query can generalize ?

*maybe using exists or not exists ?

if understand correctly, want name of cities colors same given city. if so, can use join , aggregation:

select p.city p p join      p p1      on p1.city = 'rome' ,         p1.city <> p.city ,         p1.color = p.color group p.city having count(distinct color) = (select count(distinct color) p city = 'rome'); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -