Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2006, 02:16 PM
Authorized User
 
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi
Default what should be the output of this query

Hi friends,

My table Employees contain 4 Columns:
1. EmpID
2. EmpName
3. EmpAddress &
4. DeptID
EmpName,EmpAddress & DeptID can contain duplicate records. In my table DeptID & EmpName has duplicates values. Then what should be the output of the following queries:

1. SELECT count(1) FROM Employees;
2. SELECT count(distinct 4) FROM Employees;
3. SELECT count(5) FROM Employees;
4. SELECT count(100) FROM Employees;

In all above queries, what is 1 or 4 or 5 or 100 ? If these are column numbers then what will be the output of the 4th query.

In case of query no. 1, 3 & 4, result is total no of rows present in the table. & In case of query 2, result is 1(u can place any number in place of 4).

Pls give me a proper solution...
I m really confusing ..
 
Old June 20th, 2006, 02:23 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it's easy, take away count
run this
SELECT 1 FROM Employees;
SELECT 4 FROM Employees;
SELECT 5 FROM Employees;
SELECT 100 FROM Employees;

as you can see the result is a bunch of numbers that are always the same
when you do distinct
for example
SELECT distinct 100 FROM Employees;
you only get one row, that's why when you do count(distinct 4) you get 1



------------------------------------------ http://sqlservercode.blogspot.com/
 
Old June 20th, 2006, 05:29 PM
Authorized User
 
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi
Default

Thank you sir.
I hav sent a very good solution.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query output to XML using BCP HELP!! miamikk SQL Language 3 May 15th, 2009 08:22 AM
copying a tag to output based on a query anboss XSLT 6 July 17th, 2008 11:10 AM
Recursive Query for Formatted Output Itech SQL Server 2005 11 June 12th, 2008 04:32 PM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
Sql query output to XML or HTML file miamikk SQL Language 4 June 6th, 2007 03:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.