1

Hi guys I have this situation

tabperfil
ta

bperfil.Cidade_Id -> values = 12,34,645,21

then I have a $id = 12

so I'm try to do this query

select * from tabperfil limit 0,5

but with a condiction for get the values of Cidade_Id and check with $id

if was a reverse situation I know

select * from tabperfil WHERE Cidade_Id IN ($id)

so how do something to works like this

select * from tabperfil WHERE ($id) in Cidade_Id
13
  • If you can't use proper grammar, why should we answer your question? Commented Jan 12, 2012 at 18:26
  • Have a look at mysql regular expression... you're going to be looking for scenarios where id matches the string up to the first comma, immediately follows a comma and ends with a comma, or where it follows a comma and ends the line. Commented Jan 12, 2012 at 18:27
  • nobody is perfect my friend, i m not a english expert but i try... if u can use, congrat's . i m learning Commented Jan 12, 2012 at 18:28
  • @blake305 There are a lot of non-native English speaking individuals here. Requiring proper grammar before answering a question would eliminate a lot of the help that could be provided. Commented Jan 12, 2012 at 18:28
  • 1
    @blake305 - Your edits consisted of a few capitalisations and a bit of missing code formatting. I would hardly say it was "unreadable". As the OP said in his comment, at least he's learning. These comments will likely get removed if we carry on like this, so let's leave it at that. Commented Jan 12, 2012 at 18:31

1 Answer 1

5

WHERE FIND_IN_SET($id, Cidade_Id) > 0

But you should really normalize your database. Having comma-seperated values in 1 column is asking for trouble.

Sign up to request clarification or add additional context in comments.

3 Comments

I really think that everyone who works with databases, or at least the programming of database applications, should know how to normalize a database, and not only know it, but also do it.
ok, i did this - maybe not right away but works citys => (1,3,5,7) $id = 1 $sql "SELECT * FROM TABLE WHERE (citys LIKE '$id,%' or citys LIKE '%,$id,%' OR citys LIKE '%,$id')"; thanks
Don't do that. Change your database layout so you don't have a column with comma-separated values anymore if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.