Hi,
How do I ensure that DISTINCT values of r.GPositionID are returned from the below?? - SELECT CommentImage AS ViewComment,r.GPositionID,GCustodian,GCustodianAccount,GAssetType
-
FROM @GResults r
-
LEFT OUTER JOIN
-
ReconComments cm
-
ON cm.GPositionID = r.GPositionID
-
WHERE r.GPositionID NOT IN (SELECT g.GPositionID FROM ReconGCrossReference g)
-
ORDER BY GCustodian, GCustodianAccount, GAssetType;
Thanks.
9 2196 azimmer 200
Recognized Expert New Member
Hi,
How do I ensure that DISTINCT values of r.GPositionID are returned from the below?? - SELECT CommentImage AS ViewComment,r.GPositionID,GCustodian,GCustodianAccount,GAssetType
-
FROM @GResults r
-
LEFT OUTER JOIN
-
ReconComments cm
-
ON cm.GPositionID = r.GPositionID
-
WHERE r.GPositionID NOT IN (SELECT g.GPositionID FROM ReconGCrossReference g)
-
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.
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.
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.
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.
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.
Tried the below query but returns duplicate rows... - SELECT cm.CommentImage AS ViewComment, r.GPositionID,r.GCustodian,r.GCustodianAccount,r.GAssetType
-
FROM @GResults r
-
LEFT OUTER JOIN
-
RComments cm
-
ON cm.GPositionID = r.GPositionID
-
AND cm.GPositionID = (SELECT min(GPositionID)
-
FROM RComments cm
-
WHERE GPositionID = r.GPositionID)
-
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)
azimmer 200
Recognized Expert New Member
Tried the below query but returns duplicate rows... - SELECT cm.CommentImage AS ViewComment, r.GPositionID,r.GCustodian,r.GCustodianAccount,r.GAssetType
-
FROM @GResults r
-
LEFT OUTER JOIN
-
RComments cm
-
ON cm.GPositionID = r.GPositionID
-
AND cm.GPositionID = (SELECT min(GPositionID)
-
FROM RComments cm
-
WHERE GPositionID = r.GPositionID)
-
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: -
SELECT CommentImage AS ViewComment,
-
r.GPositionID,GCustodian,
-
GCustodianAccount,GAssetType
-
FROM (
-
SELECT DISTINCT
-
GPositionID,GCustodian,
-
GCustodianAccount,GAssetType
-
FROM @GResults
-
) r
-
LEFT OUTER JOIN ReconComments cm
-
ON cm.GPositionID = r.GPositionID
-
WHERE r.GPositionID NOT IN
-
(SELECT g.GPositionID FROM ReconGCrossReference g)
-
ORDER BY GCustodian, GCustodianAccount, GAssetType;
-
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.
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?)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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.
|
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
|
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...
| |
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...
|
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
|
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...
|
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;
|
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()
|
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...
| |
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...
|
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. ...
|
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...
|
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...
|
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...
|
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...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |