January 6, 2011 at 2:50 am
can anyone explain me the functionality of "select x from tablename"?
January 6, 2011 at 2:51 am
It returns the column X for all rows in table tablename
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 6, 2011 at 3:13 am
why do people make use of "select x" instead of "select columnname"?
January 6, 2011 at 3:17 am
in topic you have specified select 'x'
so i think you wanted to know for select 'x' from tablename
the above query will return char x for all the records in the table.
normally stmts like these are used with exists/not exists
so instead of fetching all the columns in case where you want weather the data exists or not ,,simply use something like 'x',1 ,,
this will reduce the traffic and use less memory.
Pramod
SQL Server DBA | MCSE SQL Server 2012/2014
in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
January 6, 2011 at 3:20 am
deepikamm (1/6/2011)
why do people make use of "select x" instead of "select columnname"?
Errr, they don't. Select x is only possible if there's a column called x, otherwise it will throw an error.
Can you explain clearer what you're asking about?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 6, 2011 at 3:22 am
yes thats wat am asking..so it is generally used with if exixts/not exists to check for the exixtence of rows..am i correct?
January 6, 2011 at 3:22 am
yes
Pramod
SQL Server DBA | MCSE SQL Server 2012/2014
in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
January 6, 2011 at 3:25 am
@gila: i hav seen queries like" if exists ( select 'x' from tablename)" actaully i meant this query only.
January 6, 2011 at 3:32 am
thank u..:)
January 6, 2011 at 3:58 am
Is this query is SQL or VB?
in SQL you might find a: Select @x from..... if @x was declared as a variable.
but normal Select x .... means X is your column name.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
January 6, 2011 at 4:14 am
deepikamm (1/6/2011)
@gila: i hav seen queries like" if exists ( select 'x' from tablename)" actaully i meant this query only.
There's a massive difference between SELECT 'x' from table and SELECT x from table.
SELECT 'x' from table returns the constant value x for all rows. It's often used in EXISTS because the EXISTS predicate doesn't care about values, it's only concerned about whether or not there's a row.
SELECT x from table returns the column named x from the table, or an error if there is no column named x.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 6, 2011 at 4:20 am
am clear now..
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply