Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

15 Experts available now in Live!

Get 1:1 Help Now