vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL problem: select a user where membergroupids = 5,7 (https://vborg.vbsupport.ru/showthread.php?t=168950)

Yurimien 01-28-2008 10:03 AM

MySQL problem: select a user where membergroupids = 5,7
 
I want to select a list of users that have a certain membergroupid

Code:

SELECT username
FROM vb_user
WHERE membergroupids = '9'
LIMIT 0 , 30

The code works when the user only has one additional group assigned, but most of my users have 5 groups assigned. The content in the database looks like: 5,7,9,10
So how can I make sure I also select those with multiple usergroups?

--------------- Added [DATE]1201523929[/DATE] at [TIME]1201523929[/TIME] ---------------
@the one that posted a reply earlier:
This selects it only if the membergroupids start with 5. But it helped me, I've added everyone to the registered members group, and expanded it to
WHERE membergroupids IN (2 , 5 , 7 )


Thank you.

Eikinskjaldi 01-28-2008 10:51 PM

That still isn't going to help you when the membergroupids is more than one. The mysql function you want is find_in_set

[mysql]
select username from user where find_in_set('9',membergroupids)
[/mysql]

The main issue is this query is in no way optimised to use indices, and will do a full table scan.

petteyg359 01-29-2008 01:53 AM

What is the difference between find_in_set and this:

Code:

SELECT username
FROM vb_user
WHERE membergroupids LIKE '%9%'
LIMIT 0, 30


MoT3rror 01-29-2008 02:04 AM

You are going to get 29, 92, etc.


All times are GMT. The time now is 01:33 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00929 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete