January 5, 2017 at 8:15 am
There are memberid and membername in one table member.
One memberid shoud match only one membername.
How to code to find out different names with the same memberid?
January 5, 2017 at 8:22 am
Select Count(Names),MemberId,Names from Table_Sample group by MemberID Having Count(Names)>1
January 5, 2017 at 8:22 am
Use HAVING.
GROUP BY memberid HAVING COUNT( DISTINCT membername) > 1
or
GROUP BY memberid HAVING MAX(membername) <> MIN(membername)
January 5, 2017 at 8:26 am
adonetok (1/5/2017)
There are memberid and membername in one table member.One memberid shoud match only one membername.
How to code to find out different names with the same memberid?
select memberid, membername
from member
group by memberid
having count(membername) > 1
Untested and syntax unverified (I typed this from memory).
This is a very simply query. You should become friends with Books Online, his resource would have answered your question.
January 5, 2017 at 8:50 am
Lynn Pettis (1/5/2017)
adonetok (1/5/2017)
There are memberid and membername in one table member.One memberid shoud match only one membername.
How to code to find out different names with the same memberid?
select memberid, membername
from member
group by memberid
having count(membername) > 1
Untested and syntax unverified (I typed this from memory).
This is a very simply query. You should become friends with Books Online, his resource would have answered your question.
Since you're not grouping by membername, it needs to be aggregated to be in the select. You may or may not want to use a distinct count.
select memberid, COUNT(membername) AS cnt, COUNT(DISTINCT membername) AS distinct_cnt
from member
group by memberid
having count(membername) > 1
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply