473,783 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sql Distinct Unique Query

4 New Member
I have a problem with a SQL SELECT query. As far as my research goes i figured out that UNIQUE is used when you have one column that you whant unique and DISTINCT is used when you have more than one column that you want to all be unique. But i have a query where i want just some of the columns to be unique and some not. Here is the full query (It's in a stored procedure):

set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
GO
ALTER PROCEDURE [dbo].[rpt_ExecSum_Com bined_4fields](@BondGroupID int)
AS SELECT DISTINCT
SUM(dbo.Bond.Lo anAmount) AS SumOfBondValue, COUNT(dbo.Bond. BondID) AS CountOfBond, dbo.ProgressSte pType.ProgressS tepType
FROM dbo.BondGroup INNER JOIN
dbo.Transaction Table ON dbo.BondGroup.B ondGroupID = dbo.Transaction Table.BondGroup ID INNER JOIN
dbo.Bond ON dbo.Transaction Table.Transacti onID = dbo.Bond.Transa ctionID INNER JOIN
dbo.ProgressSte p ON dbo.Transaction Table.Transacti onID = dbo.ProgressSte p.TransactionID INNER JOIN
dbo.ProgressSte pType ON dbo.ProgressSte p.ProgressStepT ypeID = dbo.ProgressSte pType.ProgressS tepTypeID
WHERE (dbo.BondGroup. BondGroupID = @BondGroupID)

GROUP BY dbo.ProgressSte pType.ProgressS tepType, dbo.ProgressSte p.ProgressStepI D
HAVING (dbo.ProgressSt epType.Progress StepType = 'AIP (Approval in Principle) received') OR
(dbo.ProgressSt epType.Progress StepType = 'Grants') OR
(dbo.ProgressSt epType.Progress StepType = 'Attorney') OR
(dbo.ProgressSt epType.Progress StepType = 'Feedback received from bank')
ORDER BY dbo.ProgressSte pType.ProgressS tepType

*********
With the DISTINCT it gives me a full set of unique values but what i want is this: Every CountOfBond may have more than one SumOfBondValue and they may be the same, but if there is more than one dbo.ProgressSte pType.ProgressS tepType the query should only read it once. In other words the dbo.ProgressSte pType.ProgressS tepType is a unique value and the rest not...

Please help, my boss is on my case :)
May 4 '07 #1
0 2841

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6112
by: Florian | last post by:
Hi, I have a table that contains log data, usually around a million records. The table has about 10 columns with various attributes of the logged data, nothing special. We're using SQL Server 2000. Some of the columns (for example "category") have duplicate values throughout the records. We have a web page that queries the table to show all the unique columns, for example:
8
11114
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 and there are only 293,658 records total.
1
2491
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
5
53479
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" Thanks, Fred Zuckerman
1
3270
by: Don Bowman | last post by:
I have a table with a large number of rows (10K in the example below, but >1M in some databases). I would like to find the distinct values for one of the columns. The column is indexed. I would have expected that this would be a very fast operation, simply walking down the index. In the example below, there is only 1 unique value, but it takes 2 seconds. I would have expected more like ~50ms. explain analyze select distinct element...
4
6150
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
1
3519
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our system and thinks I am omnipotent now and can extract any data out of it in the form he wants….The truth is, though I know SOME Access, I am not a programmer…and many queries that he wants me to do have a potential of being monstrous towers of...
6
9044
by: shira | last post by:
Hi, Looking to see if someone might have an explanation for this behavior. Is it a bug? Corruption? I have been able to reproduce the problem with only 2 rows and 1 field. Here is the table: Field1 231.2
1
3736
by: RussCRM | 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 statistical purposes. I've been using Here’s the situation: I have two main tables: Guest (stores data such as GuestID, First Name, Last Name, etc.) and Services (stores data such as the type of service the guest used (Shelter Bed, Lunch, Dinner,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.