开发者

MySQL show only matched data not everything

开发者 https://www.devze.com 2023-03-29 12:52 出处:网络
I have attribute of datatype longtext in which there is on average 3 MB of plain text. Without using fulltext search or any kind I use this query:

I have attribute of datatype longtext in which there is on average 3 MB of plain text. Without using fulltext search or any kind I use this query:

select column1 from table where column1 like '%abc5%';

The output for each row is the whole content of column1. So if I would like to color matched data in PHP I would have to use:

<?php
 preg_replace('/(abc5)/i', "<b>$1</b>", $row->column1);
 ....
?>

This goes throught all content. Is the开发者_运维百科re a way that I could do something like this:

select show_first_N_matched(column1) from table where column1 like '%abc5%';

Let's say I have for example data like this:

 abc1   NA  NA  NA  NA  NA  NA
 abc2   NA  NA  NA  NA  NA  NA
 abc3   NA  NA  NA  NA  NA  NA
 abc4   NA  NA  NA  NA  NA  NA
 abc5   NA  NA  NA  NA  NA  NA
 abc4   NA  NA  NA  NA  NA  NA
 abc5   NA  NA  NA  NA  NA  NA

The first query would return everything. The second gives only this:

abc5    NA  NA  NA  NA  NA  NA
abc5    NA  NA  NA  NA  NA  NA
0

精彩评论

暂无评论...
验证码 换一张
取 消