SQL help!

Post Reply
Dibbles
Posts: 48
Joined: 11 Nov 2015, 04:43

SQL help!

Post by Dibbles » 24 Dec 2016, 02:37

I asked this in discord, but alas got no replies :( So I thought I might ask in here, as there's a better majority of you guys here than discord :)

I am trying to get a result from a table for usergroups... but the secondary_group could have multiple groups in it (2,3,6,8)

Code: Select all

SELECT username FROM users WHERE primary_group = 3 OR secondary_group = 3
anyone got any suggestions?
0 x

User avatar
Sathias
Posts: 1834
Joined: 05 Nov 2015, 16:59
Contact:

Re: SQL help!

Post by Sathias » 24 Dec 2016, 08:03

Is this what you are trying to do??

Code: Select all

SELECT username FROM users WHERE primary_group = 3 OR secondary_group IN (2,3,6,8)
0 x
"Put the damn gun down, boy. It aint no toy." - Lite

User avatar
Mini
Posts: 2933
Joined: 05 Nov 2015, 17:31
Location: Bendigo
Contact:

Re: SQL help!

Post by Mini » 24 Dec 2016, 13:08

Sorry, didn't see the post on Discord until this morning Dibbles, but agree with what Sathias has put above
0 x
Proudly supporting Player Attack through Patreon

Battle.Net - MiniSanders#1895
uPlay - mini15michael
Steam - RtD>MiniSanders
Origin - MiniSanders
Player Attack Discord

Dibbles
Posts: 48
Joined: 11 Nov 2015, 04:43

Re: SQL help!

Post by Dibbles » 24 Dec 2016, 18:44

Sathias wrote:Is this what you are trying to do??

Code: Select all

SELECT username FROM users WHERE primary_group = 3 OR secondary_group IN (2,3,6,8)
That works, but displays multiple of the same username (if they are in multiple of the groups).

ie,

User 1 is in Group 1,3,4
User 2 is in Group 2,3,6

the query above will display

username - User 1
username - User 2
username - User 2
username - User 2

Is there a way to limit to 1 per username? (I probably know it, but I just can't put my head to it right now -_-)
0 x

User avatar
Mini
Posts: 2933
Joined: 05 Nov 2015, 17:31
Location: Bendigo
Contact:

Re: SQL help!

Post by Mini » 24 Dec 2016, 18:49

Group By?

So...

Code: Select all

SELECT username FROM users WHERE primary_group = 3 OR secondary_group IN (2,3,6,8) Group By username
0 x
Proudly supporting Player Attack through Patreon

Battle.Net - MiniSanders#1895
uPlay - mini15michael
Steam - RtD>MiniSanders
Origin - MiniSanders
Player Attack Discord

Dibbles
Posts: 48
Joined: 11 Nov 2015, 04:43

Re: SQL help!

Post by Dibbles » 24 Dec 2016, 19:13

Mini wrote:Group By?

So...

Code: Select all

SELECT username FROM users WHERE primary_group = 3 OR secondary_group IN (2,3,6,8) Group By username
yep! that works wonders! cheers! Turns out I was thinking of a different way, which may not actually have worked ;)
0 x

Post Reply