SELECT and WHERE without FROM

  • Comments posted to this topic are about the item SELECT and WHERE without FROM

  • Nice question on fundamentals .. thanks

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Good question. I got to know something.

    M&M

  • Very Good basic question !

  • I looked at the question, thought, "Surely this is obvious"--went and ran it in SSMS just to be sure I wasn't missing something. It was only when I came here I realised it was talking about the missing FROM clause! 🙂

  • If the condition of the WHERE clause validates to true then the result set is returned. If it does not, the result set is empty.

    This is true only if you do not use COUNT(*):

    select count(*) cnt

    where 1 =0

    One row is returned despite the WHERE condition is false.

  • Interestingly, this gives ORA-00923 error - FROM keyword not found where expected in Oracle.

    (Hence I got it wrong!)

  • Geoff Langdon (6/23/2011)


    Interestingly, this gives ORA-00923 error - FROM keyword not found where expected in Oracle.

    (Hence I got it wrong!)

    Geoff how about:

    1 select '123' as col1

    2 from dual

    3* where 1 =1

    orhousin@BUSO> /

    COL

    ---

    123

    I was expecting this question to have almost 100% correct answers...

  • This was removed by the editor as SPAM

  • Nice question

    Thanks

  • Nice question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • You don't even need the WHERE clause. I've just done an SSIS step where I needed a single row returned, but didn't care about the contents, so I used

    SELECT 1

    and it worked fine.

  • I'd have got it right had I not accidentally clicked Parse instead of Execute! :doze:

  • Nice question. It makes me smile to see "where 1 = 1" or "while 1 = 1" in code.

  • I'm enjoying the T-SQL questions this week!

    Leonard
    Madison, WI

Viewing 15 posts - 1 through 15 (of 28 total)

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