Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:35 AM
Points: 15,510, Visits: 13,170
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 SQLKover.

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

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, December 1, 2016 3:10 AM
Points: 1,633, Visits: 2,645
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: Thursday, November 17, 2016 6:43 AM
Points: 12, Visits: 362
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


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, October 7, 2016 11:29 AM
Points: 300, Visits: 1,596
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
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 7, 2016 3:15 PM
Points: 1,860, Visits: 2,656
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


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 2:52 PM
Points: 20,083, Visits: 18,257
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


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, January 22, 2016 2:15 PM
Points: 600, Visits: 3,852
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: 2 days ago @ 5:39 PM
Points: 4,134, Visits: 2,326
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