0

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

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by prof php
0

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.

0
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.

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.