Solved

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

Posted on 2007-04-03
2
197 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
2 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 350 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 150 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now