?
Solved

What is the significance of a SELECT statement followed by the number 1 ?

Posted on 2007-04-03
2
Medium Priority
?
205 Views
Last Modified: 2010-03-20
SELECT A.Branch, A.[E-Mail] INTO tblBrEmail From tblBranchEmails A WHERE EXISTS(SELECT 1 from tblFlLNExp  B, tblBranchNotRecd C WHERE Left(B.[CPS Account Number],3)=A.Branch AND Left(B.[CPS Account Number],3)=C.Branch) ORDER BY A.Branch"

What is the significance of the 1 in the (SELECT 1 ...) ?

Can this SQL statement be written without the 1 ?
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 1400 total points
ID: 18847878
the row that is actually returned by the exists statement is irrelevant - exists looks to see if something is returned or not - most databases default to select 1 even if you specify a column - the 1 is faster to produce as it is a constant rather than row data.

so your query is saying where the sub query returns rows then show a.branch .... if it returns no rows then do not show that row from a
0
 
LVL 27

Assisted Solution

by:sujith80
sujith80 earned 600 total points
ID: 18856759
It needn't be "1". You can select any semantically correct value in the subquery used in EXISTS clause.
Say here, you can change "SELECT 1...." to any of the following, all means the same

SELECT 2 ....
SELECT 'x' ....
SELECT 'hello' ....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question