Results 1 to 3 of 3

Thread: mysql query help

  1. #1
    4x4
    Join Date
    Oct 2004
    Posts
    1,043

    mysql query help

    I have a table for user labels it contains the user_id, the group_id, and the status.

    I am building a search page that will allow the admins to find users who belong to a label and also another label (or NOT) another label.

    I understand obviously how to select * where group_id='#' but how do I make sure that the user_id for the returned row also belongs to the 2nd selected user group (or doesn't belong for that matter)?

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    that is an interesting problem, I've never done a query like that.

    I am not 100% sure it is possible with one query with your table setup as it is.

    where group_id="1" and group_id="2" doesn't work does it?

    The problem is, you have 1 field.

    I think you either have to do this with a nested query. I'm just guessing here so not sure this'll work.

    select users.user_id, users.group_id, 2users.group_id. FROM users, (select users.group_id from users where group_id = "2") as 2users WHERE users.group_id = "1"

    the other option is to change the table and store the group values as a list in one field.

    http://dev.mysql.com/doc/refman/5.1/...med-views.html
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Junior Registered
    Join Date
    Dec 2008
    Posts
    2
    just pass

Similar Threads

  1. Replies: 0
    Last Post: 01-11-2006, 07:08 AM
  2. Clear my misunderstanding: 1 MySQL database for many programs?
    By iKwak in forum Website Programming & Databases
    Replies: 4
    Last Post: 08-21-2005, 10:40 AM
  3. Replies: 0
    Last Post: 07-13-2005, 08:01 AM
  4. MySQL Query Mystery
    By willow_rd in forum Website Programming & Databases
    Replies: 6
    Last Post: 04-14-2005, 07:22 AM
  5. Excluding rows in a MySQL Query
    By nlvp in forum Website Programming & Databases
    Replies: 4
    Last Post: 06-15-2004, 08:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •