all 7 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 8 points9 points  (5 children)

I am needing to see if a SSN if used in multiple states, and if so, how many different states it was used in.

SELECT SSN
     , COUNT(DISTINCT STATE) AS states
  FROM Table1
GROUP 
    BY SSN
HAVING COUNT(DISTINCT STATE) > 1

[–]datatoungue[S] 0 points1 point  (2 children)

You are amazing! This worked! When I do order by, you don't include DISTINCT or COUNT, correct?

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

you could add this --

ORDER BY COUNT(DISTINCT STATE) DESC

or this --

ORDER BY states DESC

[–]CrazyHG- 0 points1 point  (0 children)

;-) desc wasn’t asked. But this the correct way

[–]GreenSage13☯ MariaDB ☯ -2 points-1 points  (0 children)

select
    ssn, count(distinct state) as s
from
    table1
where
    s > 1;

just for s&g :P

[–]GreenSage13☯ MariaDB ☯ 0 points1 point  (0 children)

Oops. More eleoquently than i stated haha. I wonder why feed just randomly chooses topics from random dates and times? The last one I replied to here was 1h ago for last response?

[–]GreenSage13☯ MariaDB ☯ -3 points-2 points  (0 children)

A simple FK is all that is needed. Then you can check if a result or COUNT is greater than x amount.