Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:53:05+00:00 2026-05-16T17:53:05+00:00

I have two tables Table Visitor ID Name CityName 1 Jon NY 1 Jon

  • 0

I have two tables

Table Visitor
ID Name    CityName
1  Jon     NY 
1  Jon     KY
2  Paul    NY
1  paul    TY

Table City
ID     CityName
1      NY  
2      KY
3      TY

I have to list the visitor who has visited all cities in City Table.

I took the query from web,but i do not the how it works internally.

The query is

select distinct v1.name from Visitor v1 
where not exists
          (
             select c.CityName from City c
             where not exists 
              (
                select v2.CityName from visitor v2 where
                v2.CityName=c.CityName and v1.Name=v2.Name
              )  
         )

Kinldy help me to understand the step

Iteration 1

Most outer query  v1.Name=jon 

outer query       c.CityName=NY

inner query       V2.CityName = c.CityName (NY=NY)
                  and v1.Name=v2.Name (Jon =Jon)

inner query return valye (i.e) v2.CityName=NY

NY not exists
(          
  NY
)

consition fails so nothing return

Iteration 2

    Most outer query  v1.Name=jon 

    outer query       c.CityName=NY

    inner query       V2.CityName = c.CityName (KY=NY)
                      and v1.Name=v2.Name (Jon =Jon)

    inner query return valye (i.e) v2.CityName=NULL

NY not exists
(          
  NULL
)

condition fails 
(i.e) NOT Exists is true so Jon is returned  from outer most query.

Am i right in understanding?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:53:06+00:00Added an answer on May 16, 2026 at 5:53 pm

    This is the relational division query popularised by Chris Date.

    It basically uses a double negative. To rewrite what it is doing in English: It Selects all the Visitors where there is no city that they have not visited.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Table items: | id | name | description | |
I have two tables Table FOO FooUniqueID| Year| Name| Worth| --------------------------- 1 2008 Bob
I have two tables Table Name: Graph UID1 UID2 ----------- 12 23 12 32
I have two tables: Table A: id name ------------ 1 Scott 2 Dan 3
I have two tables: table 1 fid field queryorder table 2 fid field name
Suppose I have two tables: Table A has information about the stock holdings of
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables: Table 1 has Episode and Code, with Episode as distinct.
I have two tables suppose table 1 has two columns with short names and
I have two tables: Table alpha: ID | Name --------- 1 | A 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.