﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Patrick LeBlanc / Article Discussions / Article Discussions by Author  / SELECT and WHERE without FROM / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 00:40:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Good question that was straight forward to figure out.Thanks.</description><pubDate>Fri, 02 Mar 2012 15:07:48 GMT</pubDate><dc:creator>zymos</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>I have used this before to test something... but I can't remember what it was!!!Except I usedWHERE 1=0My brain is all RAM and no HD... now where did that swapfile go to?...</description><pubDate>Mon, 27 Jun 2011 15:41:05 GMT</pubDate><dc:creator>Peter Trast</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Easy with good fundamental details...</description><pubDate>Mon, 27 Jun 2011 01:17:16 GMT</pubDate><dc:creator>Danny Ocean</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Toreador (6/24/2011)[/b][hr]I wonder which of the following (if either) is more efficient:[code="sql"]select @a = 1 where @b = 0[/code]or[code="sql"]if @b = 0 set @a = 1[/code][/quote]The best one seems to be "if" + "select" if @b = 0 (see last test):[code="sql"]declare @d datetime,@a int ,@b int,@i intset @b = 0set @d = getdate()set @i = 0while @i &amp;lt; 1000000begin if @b = 0 set @a = 1set @i = @i + 1end print datediff(millisecond,@d,getdate())set @d = getdate()set @i = 0while @i &amp;lt; 1000000begin select @a = 1 where @b = 0set @i = @i + 1end print datediff(millisecond,@d,getdate())set @d = getdate()set @i = 0while @i &amp;lt; 1000000begin if @b = 0 select @a = 1 set @i = @i + 1end print datediff(millisecond,@d,getdate())[/code]</description><pubDate>Fri, 24 Jun 2011 09:52:46 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Toreador (6/24/2011)[/b][hr]I wonder which of the following (if either) is more efficient:[code="sql"]select @a = 1 where @b = 0[/code]or[code="sql"]if @b = 0 set @a = 1[/code][/quote]"if" runs better[code="sql"]declare @d datetime,@a int ,@b int,@i intset @d = getdate()set @i = 0while @i &amp;lt; 1000000begin if @b = 0 set @a = 1set @i = @i + 1end print datediff(millisecond,@d,getdate())set @d = getdate()set @i = 0while @i &amp;lt; 1000000begin select @a = 1 where @b = 0set @i = @i + 1end print datediff(millisecond,@d,getdate())[/code]</description><pubDate>Fri, 24 Jun 2011 09:46:52 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>I wonder which of the following (if either) is more efficient:[code="sql"]select @a = 1 where @b = 0[/code]or[code="sql"]if @b = 0 set @a = 1[/code]</description><pubDate>Fri, 24 Jun 2011 08:55:17 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Carlo Romagnano (6/23/2011)[/b][hr][quote]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. [/quote]This is true only if you do not use COUNT(*):[code="sql"]select count(*)  cntwhere 1 =0[/code]One row is returned despite the WHERE condition is false.[/quote]Good One didn't know that it will still return even if where condition is false.Not to forget that basic idea of question is select still does return result even if it's missing from clause.Keep it up...Cheers</description><pubDate>Thu, 23 Jun 2011 19:08:48 GMT</pubDate><dc:creator>Dhruvesh Shah</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Easy enough!</description><pubDate>Thu, 23 Jun 2011 12:03:15 GMT</pubDate><dc:creator>AmolNaik</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]sknox (6/23/2011)[/b][hr].... the where condition filters the input to the aggregate functions, not the output from them....[/quote]True.  And of course this is because the Where clause filters input to the Select, regardless of it using an aggregate function.   That's why one may not use an alias in the Where clause.This code wouldn't work because MyData is not a real columnName in table MyVeryLongTableName.  [code="sql"]Select tbl_a.RidiculouslyComplicatedColumnName as MyData   from MyVeryLongTableName tbl_a   join AnotherVeryLongTableName tbl_b on tbl_b.key = tbl_a.keywhere MyData = 'SearchString'[/code]</description><pubDate>Thu, 23 Jun 2011 11:21:03 GMT</pubDate><dc:creator>john.arnott</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Nice question. I have used the "select '123' " or "select 5" syntax before but didn't think to ever try a where clause with it.</description><pubDate>Thu, 23 Jun 2011 10:44:32 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Terrific question!  Thanks.</description><pubDate>Thu, 23 Jun 2011 09:40:42 GMT</pubDate><dc:creator>mtillman-921105</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>straight up, fundamental question.</description><pubDate>Thu, 23 Jun 2011 09:13:18 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Carlo Romagnano (6/23/2011)[/b][hr][quote]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. [/quote]This is true only if you do not use COUNT(*):[code="sql"]select count(*)  cntwhere 1 =0[/code]One row is returned despite the WHERE condition is false.[/quote]This is true of aggregate functions, not just COUNT(*) -- the where condition filters the input to the aggregate functions, not the output from them.Try[code]select sum(5)where 1 = 0[/code]</description><pubDate>Thu, 23 Jun 2011 09:00:40 GMT</pubDate><dc:creator>sknox</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Andrew Watson-478275 (6/23/2011)[/b][hr]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[code="sql"]SELECT 1[/code]and it worked fine.[/quote]I think the concept the question was testing is; "Do you need a From clause to use a where clause?"I hope we all understand that a where clause is not needed for a SELECT statement.i.e. SELECT @ParameterName = @@Version     SELECT @ParameterName :smooooth:</description><pubDate>Thu, 23 Jun 2011 08:22:58 GMT</pubDate><dc:creator>SanDroid</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>I'm enjoying the T-SQL questions this week!</description><pubDate>Thu, 23 Jun 2011 08:15:55 GMT</pubDate><dc:creator>phonetictalk</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Nice question.  It makes me smile to see "where 1 = 1" or "while 1 = 1" in code.</description><pubDate>Thu, 23 Jun 2011 08:07:58 GMT</pubDate><dc:creator>SanDroid</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>I'd have got it right had I not accidentally clicked Parse instead of Execute! :doze:</description><pubDate>Thu, 23 Jun 2011 08:03:50 GMT</pubDate><dc:creator>jkraemer</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>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[code="sql"]SELECT 1[/code]and it worked fine.</description><pubDate>Thu, 23 Jun 2011 03:17:10 GMT</pubDate><dc:creator>Andrew Watson-478275</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Nice question, thanks.</description><pubDate>Thu, 23 Jun 2011 03:14:16 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Nice question</description><pubDate>Thu, 23 Jun 2011 02:58:08 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Having worked with MSSQL, Oracle, Db2, Sybase and Informix databases, the only ones this command will work on is MSSQL and Sybase.All the others require a FROM clause with a SELECT</description><pubDate>Thu, 23 Jun 2011 02:28:43 GMT</pubDate><dc:creator>Stewart "Arturius" Campbell</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote][b]Geoff Langdon (6/23/2011)[/b][hr]Interestingly, this gives ORA-00923 error - FROM keyword not found where expected in Oracle.(Hence I got it wrong!)[/quote]Geoff how about:  1  select '123' as col1  2  from dual  3* where 1 =1orhousin@BUSO&amp;gt; /COL---123I was expecting this question to have almost 100% correct answers...</description><pubDate>Thu, 23 Jun 2011 02:04:27 GMT</pubDate><dc:creator>paul s-306273</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Interestingly, this gives ORA-00923 error - FROM keyword not found where expected in Oracle.(Hence I got it wrong!)</description><pubDate>Thu, 23 Jun 2011 01:59:24 GMT</pubDate><dc:creator>Geoff Langdon</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>[quote]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. [/quote]This is true only if you do not use COUNT(*):[code="sql"]select count(*)  cntwhere 1 =0[/code]One row is returned despite the WHERE condition is false.</description><pubDate>Thu, 23 Jun 2011 01:27:13 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>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! :-)</description><pubDate>Thu, 23 Jun 2011 01:06:33 GMT</pubDate><dc:creator>paul.knibbs</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Very Good basic question !</description><pubDate>Thu, 23 Jun 2011 00:51:39 GMT</pubDate><dc:creator>sayyad.azhar</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Good question. I got to know something.</description><pubDate>Wed, 22 Jun 2011 22:41:14 GMT</pubDate><dc:creator>mohammed moinudheen</dc:creator></item><item><title>RE: SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Nice question on fundamentals .. thanks</description><pubDate>Wed, 22 Jun 2011 20:23:17 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>SELECT and WHERE without FROM</title><link>http://www.sqlservercentral.com/Forums/Topic1130099-405-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/73736/"&gt;SELECT and WHERE without FROM&lt;/A&gt;[/B]</description><pubDate>Wed, 22 Jun 2011 20:22:35 GMT</pubDate><dc:creator>Patrick_LeBlanc</dc:creator></item></channel></rss>