qadenza
qadenza

Reputation: 9293

select rows containing a string in a specific column

Content of entire pos column is home01+home03 or home02+home04.
I need to select rows where pos contains home01.

$pos = 'home01';
$stmt = $db->query("select * from banners where pos contains '" . $pos . "'");

Nothing is selected.
Also I need to avoid LIKE statement because of large table.
Any help?

Upvotes: 2

Views: 265

Answers (2)

Nishant Nair
Nishant Nair

Reputation: 2007

You can use match againts

ALTER TABLE table_name ADD FULLTEXT(pos);

SELECT * FROM banners MATCH(pos) AGAINST('+$pos+');

Upvotes: 2

Shafiqul Islam
Shafiqul Islam

Reputation: 5690

use this query

select * from banners where pos like'%" . $pos . "'";

this query return all row where first match home01

Upvotes: 0

Related Questions