what is select 'X'?

  • can anyone explain me the functionality of "select x from tablename"?

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • why do people make use of "select x" instead of "select columnname"?

  • 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/

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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?

  • yes

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/

  • @gila: i hav seen queries like" if exists ( select 'x' from tablename)" actaully i meant this query only.

  • thank u..:)

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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