[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-04-03
2
Medium Priority
?
206 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

649 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