Akp
Akp

Reputation: 269

Mysql query to find only exact value?

I have value in my db like 1,12,13,25,44,414,2114

I have to find exact 14 from the db. but it also return the value 414 and 2114 but i want exact 14. How can i achieve this through sql query Please help i have tried this but didn't worked.

Select * from tb_name where columnNAme like '%value%'

Upvotes: 1

Views: 998

Answers (3)

Oto Shavadze
Oto Shavadze

Reputation: 42793

If you want search exactly 14, then you need search %,14,%, but 14 may appears at start or at end of string, so you need add commas to column also.

Well, you can use:

select * from tb_name where concat(',',columnNAme ,',') like '%,14,%'

Side note, comma separated values in one column is bad database design

Upvotes: 2

Popovici Cosmi
Popovici Cosmi

Reputation: 53

Select * from tb_name where columnNAme like 'value'
% - The percent sign represents zero, one, or multiple characters

Upvotes: 2

James
James

Reputation: 310

SELET * FROM database WHERE column LIKE 14 should work fine, just double checked it on my database.

If this doesn't work can you show your query please?

Above answer is correct, I didn't see your query before I posted this.

Upvotes: 0

Related Questions