Can we write a SELECT query without using the keyword FROM

  • I got this as a interview question, Can you please tell me if we can write a working

    SELECT statement without FROM keyword.

    Can you give me an example?

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • SELECT @@VERSION

    AND

    SELECT 'HELLO WORLD'

    These are the kinds of statements that are on top of my head...


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • Thank You, I got my answer.

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • Z@f (5/21/2010)


    Thank You, I got my answer.

    You are Welcome 🙂


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • You can turn use this to turn SQL into the most expensive calculator ever 😀

    SELECT 5000/34.2

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • SELECT also serves as a synonym for SET.

    declare @a int

    select @a = 5

    print @a

    Rob Schripsema
    Propack, Inc.

  • The best use of SELECT without FROM

    IS DRAWING PICTURES

    (switch to text output before execution):

    select '0000^===========\0000' as [picture]

    union select '000/^\__________\\000'

    union select '00//0\\__________\\00'

    union select '0//000\\__________\\0'

    union select '//00000\\__________\\'

    union select '====================='

    union select '|0000000000000000000|'

    union select '|0====00000========0|'

    union select '|0!--!00000! |) (!0|'

    union select '|0!)(!00000! | !0|'

    union select '|0!__!00000!______!0|'

    union select '====================='

    union select '====================='

    :-D:-D:-D:-D:-D:-D:-D:-D

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • elutin (5/21/2010)


    The best use of SELECT without FROM

    IS DRAWING PICTURES

    (switch to text output before execution):

    select '0000^===========\0000' as [picture]

    union select '000/^\__________\\000'

    union select '00//0\\__________\\00'

    union select '0//000\\__________\\0'

    union select '//00000\\__________\\'

    union select '====================='

    union select '|0000000000000000000|'

    union select '|0====00000========0|'

    union select '|0!--!00000! |) (!0|'

    union select '|0!)(!00000! | !0|'

    union select '|0!__!00000!______!0|'

    union select '====================='

    union select '====================='

    :-D:-D:-D:-D:-D:-D:-D:-D

    Ah -- but did you realize that you need to use "UNION ALL" instead of just "UNION" statements here -- otherwise, SQL will sort each selected "row" in order to weed out duplicates, and the picture gets output all wierd. (Try it!). UNION ALL doesn't check for duplicates, so it comes out right.

    Otherwise--very cute. Didn't know techies could also be artists!

    Rob Schripsema
    Propack, Inc.

  • When you said the most expensive calculator. I have a question.

    When we need to do some complex arithmetic in SQL Server .. while processing and filtering out the

    data ? what alternatives we have ?

    Can we just go n keep ona dding stuff like

    SELECT Name, Age, ID

    FROM Employees

    WHERE ((('BasicSalary'+'TaxesRefunded')/2456)+765) <= 567

    ?????

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • @@ Garadin

    When you said the most expensive calculator. I have a question.

    When we need to do some complex arithmetic in SQL Server .. while processing and filtering out the

    data ? what alternatives we have ?

    Can we just go n keep ona dding stuff like

    SELECT Name, Age, ID

    FROM Employees

    WHERE ((('BasicSalary'+'TaxesRefunded')/2456)+765) <= 567

    ?????

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • Yeah, doing things like that is no problem.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Ah -- but did you realize that you need to use "UNION ALL" instead of just "UNION" statements here -- otherwise, SQL will sort each selected "row" in order to weed out duplicates, and the picture gets output all wierd. (Try it!). UNION ALL doesn't check for duplicates, so it comes out right.

    :w00t::w00t::w00t::w00t::w00t:

    Hey man, you are trying to dictate artist how to draw? That what government did and does in some contries (USSR, China, North Korea etc.). There is a democracy here! You don't like wierd pictures? What about Monet, Malevich, Paul Gauguin and man many others? Impressionism, Primitivism, Cubism or Abstraction?

    I believe you would tell Malevich to use a ruller to draw his Black Square, otherwise it looks a bit uneven...

    :-P:-P:-P:-P:-P:-P:-P:-P

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • elutin (5/22/2010)


    Hey man, you are trying to dictate artist how to draw? That what government did and does in some contries (USSR, China, North Korea etc.). There is a democracy here! You don't like wierd pictures? What about Monet, Malevich, Paul Gauguin and man many others? Impressionism, Primitivism, Cubism or Abstraction?

    I believe you would tell Malevich to use a ruller to draw his Black Square, otherwise it looks a bit uneven...

    :-P:-P:-P:-P:-P:-P:-P:-P

    We are Borg [aka SQL]. Resistance is Futile. You WILL be assimilated....

    Rob Schripsema
    Propack, Inc.

  • My favourite SELECT without a FROM clause (sadly this does not draw pictures):

    SELECT 'penguins'

    WHERE 1 = 2

    HAVING 0 < 1;

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply