Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 a very simple question

Author  Topic 

aylin_sk
Starting Member

25 Posts

Posted - 2005-01-25 : 03:45:19
Why do we use "1" in sql?

Select 1 from Table

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-01-25 : 03:48:40
quote:
Originally posted by aylin_sk

Why do we use "1" in sql?

Select 1 from Table



what do you mean?

your query will return n-number of 1's depending on the number of rows returned

--------------------
keeping it simple...
Go to Top of Page

aylin_sk
Starting Member

25 Posts

Posted - 2005-01-25 : 03:54:26
Does it mean that selecting 1 means from a table returning number of rows??
Go to Top of Page

guidomarcel
Starting Member

5 Posts

Posted - 2005-01-25 : 04:14:00
If you just want to do an existence check and you are not interested on any field values it is more performant to select a constant (1 or "1", "2", etc.).
Regards
GuidoMArcel

The free SQL Code Formatter on www.sqlinform.com
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-01-25 : 04:43:23
quote:
Originally posted by aylin_sk

Does it mean that selecting 1 means from a table returning number of rows??



actually not exactly, what i mean is that if you do a
select 1 from table1
you're returning the value 1 n-number of times, let say you have 10 rows in table1, then you'll get 10 rows with one column having the value 1.

to provide you with the number of rows:
a. issue a select @@rowcount right after the select statement
b. select count(*) from table1


you might want to rephrase your question, is that what you were asking?

--------------------
keeping it simple...
Go to Top of Page

aylin_sk
Starting Member

25 Posts

Posted - 2005-01-26 : 05:00:42
Thanks a lot..
Go to Top of Page
   

- Advertisement -