473,587 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return DISTINCT Values

63 New Member
Hi,

How do I ensure that DISTINCT values of r.GPositionID are returned from the below??

Expand|Select|Wrap|Line Numbers
  1. SELECT CommentImage AS ViewComment,r.GPositionID,GCustodian,GCustodianAccount,GAssetType
  2. FROM @GResults r
  3. LEFT OUTER JOIN
  4. ReconComments cm
  5. ON cm.GPositionID = r.GPositionID
  6. WHERE r.GPositionID NOT IN (SELECT g.GPositionID FROM ReconGCrossReference g)
  7. ORDER BY GCustodian, GCustodianAccount, GAssetType;
Thanks.
Aug 22 '07 #1
9 2196
azimmer
200 Recognized Expert New Member
Hi,

How do I ensure that DISTINCT values of r.GPositionID are returned from the below??

Expand|Select|Wrap|Line Numbers
  1. SELECT CommentImage AS ViewComment,r.GPositionID,GCustodian,GCustodianAccount,GAssetType
  2. FROM @GResults r
  3. LEFT OUTER JOIN
  4. ReconComments cm
  5. ON cm.GPositionID = r.GPositionID
  6. WHERE r.GPositionID NOT IN (SELECT g.GPositionID FROM ReconGCrossReference g)
  7. ORDER BY GCustodian, GCustodianAccount, GAssetType;
Thanks.
What do you want the other fields be? First/Last/Any/Other? I mean that if you return the r.GPositionID, some values need to get associated with CommentImage, GCustodian, GCustodianAccou nt, and GAssetType as well.
Aug 22 '07 #2
obrienkev
63 New Member
What do you want the other fields be? First/Last/Any/Other? I mean that if you return the r.GPositionID, some values need to get associated with CommentImage, GCustodian, GCustodianAccou nt, and GAssetType as well.

r.GPositionID,G Custodian,GCust odianAcc ount,GAssetType are all from the one table.
So I want the distinct values of this table returned.

thanks.
Aug 22 '07 #3
azimmer
200 Recognized Expert New Member
r.GPositionID,G Custodian,GCust odianAcc ount,GAssetType are all from the one table.
So I want the distinct values of this table returned.

thanks.
If you want all distinct combinations put the DISTINCT keyword after SELECT, i.e.: SELECT DISTINCT CommentImage AS ViewComment,r.G PositionID,GCus todian,GCustodi anAccount,GAsse tType
...

If it's not what you want, give us examples, pls.
Aug 22 '07 #4
obrienkev
63 New Member
If you want all distinct combinations put the DISTINCT keyword after SELECT, i.e.: SELECT DISTINCT CommentImage AS ViewComment,r.G PositionID,GCus todian,GCustodi anAccount,GAsse tType
...

If it's not what you want, give us examples, pls.
Yes I want to do the above query but SQL Server gives this error...
The text, ntext, or image data type cannot be selected as DISTINCT

CommentImage field has datatype of image.

Thanks.
Aug 23 '07 #5
azimmer
200 Recognized Expert New Member
Yes I want to do the above query but SQL Server gives this error...
The text, ntext, or image data type cannot be selected as DISTINCT

CommentImage field has datatype of image.

Thanks.
That's bad but understandable (on SQL's side): what do you mean by distinct images? If you do mean they have to be different you'll have to find a workaround. If you don't, put all of your select but the image one into an "inner" select in the FROM clause, join the "inner" select with the table that contains the image and in an "outer" select select (all) fields from the "inner" select and the image from the other one.
Hope it helps. Without knowing the table structure and your exact specs it's hard to be more specific.
Aug 24 '07 #6
obrienkev
63 New Member
Tried the below query but returns duplicate rows...

Expand|Select|Wrap|Line Numbers
  1. SELECT cm.CommentImage AS ViewComment, r.GPositionID,r.GCustodian,r.GCustodianAccount,r.GAssetType
  2. FROM @GResults r
  3. LEFT OUTER JOIN
  4.     RComments cm
  5.     ON cm.GPositionID = r.GPositionID
  6. AND cm.GPositionID = (SELECT min(GPositionID)
  7.               FROM RComments cm
  8.               WHERE GPositionID = r.GPositionID)
  9. order by r.GPositionID
Here's the tables structure:

RComments Tbl:

RCommentsID int PK,
CommentImage image,
GPositionID int FK

@GResults Tbl:

GPositionID int PK,
GCustodian varchar(250),
GCustodianAccou nt varchar(250),
GAssetType varchar(250)
Aug 24 '07 #7
azimmer
200 Recognized Expert New Member
Tried the below query but returns duplicate rows...

Expand|Select|Wrap|Line Numbers
  1. SELECT cm.CommentImage AS ViewComment, r.GPositionID,r.GCustodian,r.GCustodianAccount,r.GAssetType
  2. FROM @GResults r
  3. LEFT OUTER JOIN
  4.     RComments cm
  5.     ON cm.GPositionID = r.GPositionID
  6. AND cm.GPositionID = (SELECT min(GPositionID)
  7.               FROM RComments cm
  8.               WHERE GPositionID = r.GPositionID)
  9. order by r.GPositionID
Here's the tables structure:

RComments Tbl:

RCommentsID int PK,
CommentImage image,
GPositionID int FK

@GResults Tbl:

GPositionID int PK,
GCustodian varchar(250),
GCustodianAccou nt varchar(250),
GAssetType varchar(250)
My suggestion:
Expand|Select|Wrap|Line Numbers
  1. SELECT CommentImage AS ViewComment,
  2.         r.GPositionID,GCustodian,
  3.         GCustodianAccount,GAssetType
  4. FROM (
  5.       SELECT DISTINCT
  6.         GPositionID,GCustodian,
  7.         GCustodianAccount,GAssetType
  8.       FROM @GResults
  9.      ) r
  10.      LEFT OUTER JOIN ReconComments cm
  11.         ON cm.GPositionID = r.GPositionID
  12. WHERE r.GPositionID NOT IN
  13.     (SELECT g.GPositionID FROM ReconGCrossReference g)
  14. ORDER BY GCustodian, GCustodianAccount, GAssetType;
  15.  
Aug 24 '07 #8
obrienkev
63 New Member
Returned rows from RComments table of the same GPositionID.

GPositionID and GCustodian are in the one table.
CommentImage is from a related table.

There is a M:M relation.

Here's the tables structure:

RComments Tbl:

RCommentsID int PK,
CommentImage image,
GPositionID int FK

@GResults Tbl:

GPositionID int PK,
GCustodian varchar(250),
GCustodianAccou nt varchar(250),
GAssetType varchar(250)

Thanks.
Aug 27 '07 #9
azimmer
200 Recognized Expert New Member
Returned rows from RComments table of the same GPositionID.

GPositionID and GCustodian are in the one table.
CommentImage is from a related table.

There is a M:M relation.

Here's the tables structure:

RComments Tbl:

RCommentsID int PK,
CommentImage image,
GPositionID int FK

@GResults Tbl:

GPositionID int PK,
GCustodian varchar(250),
GCustodianAccou nt varchar(250),
GAssetType varchar(250)

Thanks.
Especially if it's an M:M relation (technically the same as N:M), my problem is the same as SQL Server's: we'd need to compare and distinguish images... (It seems that you want DISTINCT images -- that's what the core of the problem is, isn't it?)
Aug 27 '07 #10

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

Similar topics

2
3928
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my skills, especially with MySQL are rudimentary</disclaimer> However my code (link below) fails, the nested database call does not return any data and...
4
6105
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...
8
11093
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.
5
53381
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
7
4084
by: Johnathan Doe | last post by:
I can google search to find the range of values that can be represented in a float by reading up on the IEEE std, but is that the same as how many distinct values that can go in a float type? For instance, floats can distinguish 0.000001 and 0.000002. If I started with 0.000001 and kept adding 0.000001 until I hit some maximum value...
5
6889
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has the described properties. If I use the same statement in a select into statement (see the second select) I get several datasets with the described...
17
4572
by: pbd22 | last post by:
Hi. How does one return a range of rows. I know that "Top 5" will return rows 0 - 5 but, how do I get 6 - 10? thanks
1
3505
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...
9
3205
by: lenygold via DBMonster.com | last post by:
I have the following trigger: --#SET TERMINATOR ! CREATE TRIGGER CROSS_REFF_TRIG AFTER INSERT ON NEW_CATALOG REFERENCING NEW AS nnn FOR EACH ROW MODE DB2SQL BEGIN ATOMIC DECLARE reason VARCHAR(70); DECLARE OUT_SQLCODE1 INTEGER;
49
2693
by: Davy | last post by:
Hi all, I am writing a function, which return the pointer of the int. But it seems to be wrong. Any suggestion? int * get_p_t(int t) { return &t; } int main()
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
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. ...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
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...
1
5719
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...
0
3845
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...
1
2364
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
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.