Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

SELECT and WHERE without FROM Expand / Collapse
Author
Message
Posted Thursday, June 23, 2011 3:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 12:52 PM
Points: 13,636, Visits: 11,509
Nice question, thanks.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1130241
Posted Thursday, June 23, 2011 3:17 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 3:02 AM
Points: 1,298, Visits: 2,270
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.
Post #1130243
Posted Thursday, June 23, 2011 8:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 8:10 AM
Points: 10, Visits: 29
I'd have got it right had I not accidentally clicked Parse instead of Execute!
Post #1130445
Posted Thursday, June 23, 2011 8:07 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,228, Visits: 1,046
Nice question. It makes me smile to see "where 1 = 1" or "while 1 = 1" in code.
Post #1130453
Posted Thursday, June 23, 2011 8:15 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 9:52 AM
Points: 272, Visits: 1,393
I'm enjoying the T-SQL questions this week!

Leonard
Madison, WI
Post #1130461
Posted Thursday, June 23, 2011 8:22 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,228, Visits: 1,046
Andrew Watson-478275 (6/23/2011)
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 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

Post #1130467
Posted Thursday, June 23, 2011 9:00 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:39 PM
Points: 1,382, Visits: 1,752
Carlo Romagnano (6/23/2011)
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.


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
select sum(5)
where 1 = 0

Post #1130510
Posted Thursday, June 23, 2011 9:13 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:20 PM
Points: 18,064, Visits: 16,099
straight up, fundamental question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1130538
Posted Thursday, June 23, 2011 9:40 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 3:46 PM
Points: 598, Visits: 3,821
Terrific question! Thanks.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Post #1130583
Posted Thursday, June 23, 2011 10:44 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 10:56 AM
Points: 3,417, Visits: 2,035
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.
Post #1130652
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse