Results 1 to 4 of 4

Thread: How eliminate commas in query and get particular id

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up How eliminate commas in query and get particular id

    Dear friends,

    This is my table tblGroups

    intGroupId intUserId

    1 1,2,3

    2 1,3

    3 2,3,4



    In this table i need to get intGroupId that where intUserId=2. That is "select intGroupId from tblGroups where intUserId=2."

    This query is possible to get intGroupId from the above table. I need this one. What query is possible to get the id.

    Hope yours reply.

    Thanks

    Ashok
    Failing to plan is Planning to fail

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How eliminate commas in query and get particular id

    That's a very bad schema. For a many:many relationship you should have three tables: User, Group and UserGroup. The UserGroup table has a foreign key from each of the User and Group tables, so that constitutes the relationship. You can then simply query the UserGroup table exactly as you have shown without any need for breaking up a composite value like that.

    I'm sure what you're asking for can be done but I don't know offhand how to do it so I'll leave that to others. It will be messy though and, if you had the appropriate schema, unnecessary. I suggest that you change your database schema if it's at all possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: How eliminate commas in query and get particular id

    Hi dude thanks for your reply.

    Yes its correct i got it. You know any best schema for this condition that is Single users in multiple groups .Is it affects performance??

    Can you tell that without affect the perfomance we can do this dude.

    Thanks

    Ashok
    Failing to plan is Planning to fail

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How eliminate commas in query and get particular id

    I already told you what the best schema is. Performing a join will always incur a small performance hit but that doesn't mean that you should avoid using multiple tables. Having to break a string up into multiple numbers will affect performance more so you're far better of with the three separate tables where the join table contains nothing but the foreign keys.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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