SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Distinct Statement Mystery


Distinct Statement Mystery

Author
Message
fgrubercpa
fgrubercpa
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 88
I have a db of Contacts - it's real simple, NAME, ADDRESS, CITY, ST, ZIP, etc...


I CAN DO

SELECT ST
FROM TABLE


and I get all of the ST from every record.

When I try
SELECT DISTINCT ST
FROM TABLE

it displays what looks like a complete listing of DISTINCT CITY values

but it is UNDER THE COLUMN HEADING 'ST'

It's like the values next to ST (CITY) has replaced the desired query for some reason,
any suggestions?

thx
Spatio
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15098 Visits: 18597
fgrubercpa (7/14/2014)
I have a db of Contacts - it's real simple, NAME, ADDRESS, CITY, ST, ZIP, etc...


I CAN DO

SELECT ST
FROM TABLE


and I get all of the ST from every record.

When I try
SELECT DISTINCT ST
FROM TABLE

it displays what looks like a complete listing of DISTINCT CITY values

but it is UNDER THE COLUMN HEADING 'ST'

It's like the values next to ST (CITY) has replaced the desired query for some reason,
any suggestions?

thx
Spatio


Quick questions,
a. can you post the ddl for the table
b. what do you get from the following query
SELECT 
T.ST
,ROW_NUMBER() OVER (PARTITION BY T.ST ORDER BY (SELECT NULL)) AS ST_RID
FROM [schema].[TABLE] T


fgrubercpa
fgrubercpa
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 88
Running the T-SQL you gave, I got 2 columns entitled ST and SR_RID

under ST there seems to be a mix of cities combined with the standard 2 letter postal abbrev for states , i.e. FL, GE MN, ETC...


Some of the records even returned Addresses under the ST Column, in addition to some having the City, as opposed to state info.


If somehow how I imported this wrong and the data was placed in the the wrong columns in some fields, I could understand, but doing SELECT *, I can view all the records and the ST Column shows only the 2 Ltr Postal Abbrevs. So ????

I apologize, I did not understand what you meant by my 'ddl'.
Thanks
Spatio
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search