473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Select Unique Distinct records for Column

Im trying to run a query that will pull distinct data not for the
entire select query but for a single column. Here is my sql statement
below. Why is it not working? It is probably something stupid. Thanks
for your help in advance

SELECT Count(MastrQualityTbl.[WORK NUMBER]) AS [TOTAL WORK RECEIVED],
MastrQualityTbl.USERID, MastrQualityTbl.FIRSTNAME,
MastrQualityTbl.LASTNAME, MastrQualityTbl.TEAM_NAME
FROM MastrQualityTbl as c1
WHERE NOT EXISTS (SELECT MastrQualityTbl.[WORK NUMBER] from
MastrQualityTbl WHERE MastrQualityTbl.[WORK NUMBER] = c1.WORK NUMBER)
and
WHERE (((MastrQualityTbl.DATE) Between
[Forms]![DashBoardForm]![FromDate] And
[Forms]![DashBoardForm]![ToDate]) AND ((MastrQualityTbl.CATEGORY) In
('NEW BUSINESS')))
GROUP BY MastrQualityTbl.USERID, MastrQualityTbl.FIRSTNAME,
MastrQualityTbl.LASTNAME, MastrQualityTbl.TEAM_NAME;

Im trying to count only the unique WORK NUMBERS in this select
statement.

Nov 7 '06 #1
1 6049
ph*******@gmail.com wrote:
Im trying to run a query that will pull distinct data not for the
entire select query but for a single column. Here is my sql statement
below. Why is it not working? It is probably something stupid. Thanks
for your help in advance

SELECT Count(MastrQualityTbl.[WORK NUMBER]) AS [TOTAL WORK RECEIVED],
MastrQualityTbl.USERID, MastrQualityTbl.FIRSTNAME,
MastrQualityTbl.LASTNAME, MastrQualityTbl.TEAM_NAME
FROM MastrQualityTbl as c1
WHERE NOT EXISTS (SELECT MastrQualityTbl.[WORK NUMBER] from
MastrQualityTbl WHERE MastrQualityTbl.[WORK NUMBER] = c1.WORK NUMBER)
and
WHERE (((MastrQualityTbl.DATE) Between
[Forms]![DashBoardForm]![FromDate] And
[Forms]![DashBoardForm]![ToDate]) AND ((MastrQualityTbl.CATEGORY) In
('NEW BUSINESS')))
GROUP BY MastrQualityTbl.USERID, MastrQualityTbl.FIRSTNAME,
MastrQualityTbl.LASTNAME, MastrQualityTbl.TEAM_NAME;

Im trying to count only the unique WORK NUMBERS in this select
statement.

Replied in microsoft.public.sqlserver.programming

Please do not multi-post.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Nov 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the...
2
by: Keith | last post by:
I don't know what the correct syntax is to do what I want with the DISTINCT function (if it's actually possible). I have a query which displays a variety of fields from a variety of tables...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
9
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
0
by: philip260 | last post by:
Im trying to run a query that will pull distinct data not for the entire select query but for a single column. Here is my sql statement below. Why is it not working? It is probably something...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.