Results 1 to 2 of 2

Thread: More of an SQL question

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024

    More of an SQL question

    I already have PHP do this but I am trying to trim the code down a bit.

    I have 2 tables one contains users ids and group ids, another contains group ids and group names. I want to run a querry that gets all the group ids for a specific user and then uses that result to get the group name from the other table.

    So something like

    SELECT group_name FROM group_table WHERE group_id = (SELECT group_id WHERE user_id=3)

    Possible?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: More of an SQL question

    Code:
    UserGroups
    - UserID
    - GroupID
    
    Groups
    - GroupID
    - GroupName
    
    SELECT GroupName
    FROM UserGroups
    	INNER JOIN Groups ON (Groups.GroupID = UserGroups.GroupID)
    WHERE UserGroup.UserID = [some number]

Posting Permissions

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



Click Here to Expand Forum to Full Width