tags:

views:

76

answers:

6
+1  Q: 

Having a number in

Can someone give me a query that will return as a result rows ID 1 & 3?

ID Name Hidden 
1 Mika 1,4,2 
2 Loca 0 
3 Nosta 4 
4 Like 2 

Something like this SELECT * FROM table WHERE Hidden HAVING(4)

A: 
SELECT * FROM table WHERE Hidden LIKE '%4%'

the % are wildcards.

Samuel
That will also match '13,14,15'.
Christoffer Hammarström
This would match any value containing 4, eg: 34, 44, and so on.
jweyrich
Thanks Samuel, i'm sorry because i didn't referred to it before, but i can't use LIKE due to some performance functionality, Thanks again
Wiika
A: 

Full Text Search might be a reasonable solution for this as long as you use the correct word breaks.

Mark Wilkins
Wiika
@Wiika: There are probably quite a few ways. One thing with full text search is that it can be extremely high performance. So if you are dealing with large data sets, it is a nice solution.
Mark Wilkins
+7  A: 
SELECT * FROM table WHERE FIND_IN_SET('4',Hidden);

docs for FIND_IN_SET

dnagirl
it seem to be working for me, Thanks
Wiika
just a note: single quotes are optional if you're looking for a number.
jweyrich
ya, i'm only looking for numbers , thanks again i really appreciate
Wiika
A: 

Either go with Full Text Search, as suggested, or

Spin the Hidden values off into a separate table, with the ID of current row.

Eg, Mika would have three entries in this table

ID = 1, Hidden =1
ID = 1, Hidden =4
ID = 1, Hidden =2

Then you could return results against this spin off table.

Jammin
+1  A: 

SELECT * FROM table WHERE CONCAT(',',Hidden,',') LIKE '%,4,%'

or you can avoid using LIKE like this

SELECT * FROM table WHERE INSTR(CONCAT(',',Hidden,','), ',4,') > 0

this will not get things like 40, 14, etc, but you need to make sure there are no spaces in the Hidden field (eg, 1, 4, 5 or update the concat and LIKE function accordingly.

oedo
A: 

You may also want to consider normalizing the table and storing these "hidden" values in a separate table with an index on the apropriate column. Depending on the number of rows you have that would be much faster:

ID Hidden
1  1
1  4
1  2 
3  4 
4  2 

and:

SELECT DISTINCT table.* FROM table, hidden_table WHERE table.ID = hidden_table.ID AND hidden_table.hidden = 4
RoToRa