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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.