hello...,

SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS (
    SELECT * FROM cities WHERE NOT EXISTS (
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type));

please any one help me to understand this query... and what would be the output of this.
and please anyone suggest me tutorials for this type of query


thanks

Recommended Answers

All 3 Replies

you need to read this.

i just take this query from the site you suggested. but i m not being able to understand what this query is doing. what will b the output step by step.

SELECT * FROM cities_stores
WHERE cities_stores.city = cities.city
AND cities_stores.store_type = stores.store_type

This one is starightforward and m sure you do undestand it right?

The value returned in the query above becomes a condition for this one:

SELECT * FROM cities WHERE NOT EXISTS

(Selects all the rows where the cities_store value doesn't exist)

Then the value returned by the previous query becomes a condition(select rows without the value returned) for this one:

SELECT DISTINCT store_type FROM stores s1
WHERE NOT EXISTS

Selects store_type of different values(If two rows contain the same value it only selects one) from stores nicknamed s1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.