Solved

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

Posted on 2007-04-03
2
200 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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