SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using IN in reverse?

    Not sure if this is possible, but I'm storing my values in a longtext field as:
    1,2,4,5

    later I want to retrieve by using:
    WHERE 4 IN(lngtxt)

    For some reason, this is only working when the first value matches that of my criteria, for example:
    lngtxt = 4,2,6,1
    WHERE 4 IN(lngtxt) -> 1 result

    However, if it's 'inside' the value, it doesn't work:
    lngtext=2,5,4,5
    WHERE 4 IN(lngtxt) -> no results

    So, what's the proper way of doing this?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by solepixel View Post
    So, what's the proper way of doing this?
    the proper way is with a one-to-many related table

    any time you store multiple values in a single column, you are almost certainly making a design error

    search "first normal form" for further information

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was afraid I was going to have to go back and do that. Thanks!


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
  •