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

  • SEARCH
  • Home
  • 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 7743269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:29:24+00:00 2026-06-01T09:29:24+00:00

here is the query SELECT * FROM customers WHERE NOT EXISTS ( SELECT 1

  • 0

here is the query

SELECT * FROM customers  
WHERE 
     NOT EXISTS 
     (     
          SELECT 1 FROM brochure_requests     
          WHERE  brochure_requests.first_name = customers.customer_first_name AND    
          brochure_requests.last_name = customers.customer_last_name
     )

This query works just fine but I am not sure why it works. In the NOT EXISTS part SELECT 1 what is the 1 for. When I ran this query

select 1 from test2

Here were the results:

1
-----
1
1
1
1
1
1
1
1
1
1
1
..

How does the not exists query work?

  • 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-06-01T09:29:26+00:00Added an answer on June 1, 2026 at 9:29 am

    The compiler is smart enough to ignore the actual SELECT in an EXISTS. So, basically, if it WOULD return rows because the filters match, that is all it cares about…the SELECT portion of the EXISTS never executes. It only uses the EXISTS clauses for evaluation purposes

    I had this misconception for quite some time since you will see this SELECT 1 a lot. But, I have seen 42, *, etc….It never actually cares about the result, only that there would be one :). The key to keep in mind that SQL is a compiled language, so it will optimize this appropriately.

    You could put a 1/0 and it will not throw a divide-by-zero exception…thus further proving that the result set is not evaluated. This is shown in this SQLFiddle

    Code from Fiddle:

    CREATE TABLE test (i int)
    CREATE TABLE test2 (i int)
    
    INSERT INTO test VALUES (1)
    INSERT INTO test2 VALUES (1)
    
    SELECT i
    FROM test
    WHERE EXISTS
    (
      SELECT 1/0
      FROM test2
      WHERE test2.i = test.i
    )
    

    And finally, more to your point, the NOT simply negates an EXISTS, saying to IGNORE any rows that match

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

Sidebar

Related Questions

Here is my query select * from table1 inner join table2 on table1.typeId=table2.typeId; This
here is the query I am stuck with: SELECT * FROM customers WHERE salesmanid
Here is my query select t1.*, t2.name as customer, t2.name as vendor from order
Here is my query Select Gender from Table The result pane shows 1 1
Here is my Query : select EmployeeName, EmployeeSalary from Employee2 for xml path('EmployeeDetails') returns
Here is the pseudo-code for my inline query in my code: select columnOne from
Here is the query that I am working on: SELECT `unitid`, `name` FROM apartmentunits
Here is my LINQ query: (from o in entities.MyTable orderby o.MyColumn select o.MyColumn).Distinct(); Here
We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM
I'm using this Query but I have it wrong... SELECT * FROM [Orders] JOIN

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.