Jump to content

[SOLVED] Help with LIKE statement...what am I not seeing?


JD*

Recommended Posts

Hey all,

 

Been bashing my head against this for a bit...I'm trying to grab users from a particular building using a LIKE statement, but I think I need some outside perspective.

 

For my site, users are assigned to building in a column like:

 

User Name Building
Joe Smith 1,2
Jane Smith 2,4
Don Ho 12,3

 

What I'm looking to do is pull all users where the building, lets say, is 2. Currently, doing this:

 

SELECT * FROM table WHERE building LIKE "%2%"

 

Is going to return both Joe Smith, Jane Smith AND Don Ho, when I only want Joe and Jane. If I add in a "%,2,%", I'm not going to get Jane Smith because there is no comma in front of her building number.

 

Now, I know I can put a 0 in front of my single digit numbers, but before I do so, I wanted to know if I'm missing anything. This all ties into a function where I pass the current building I'm looking for, so it needs to be fairly flexible.

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.