Below is the table called list
:
Column Name Data Type
id (Int)
user_one (String)
user_two (String)
I would like to scan for a user in user_one
and user_two
column
.
In return I would like to get back the first 100 records and a flag that says there are more records.
Solution #1:
ALTER TABLE list ADD FULLTEXT KEY `full_name` (`user_one`,`user_two`);
SELECT * FROM list WHERE MATCH(user_one, user_two) AGAINST ('john');
I believe solution 1 will perform better, but I am not sure how to add a limit
of 100 and get a flag
.
Solution #2:
SELECT * FROM list
WHERE "john" LIKE Concat(Concat('%',user_one),'%')
OR "john" LIKE Concat(Concat('%',user_two),'%')
ORDER BY id
LIMIT 50
I think solution #2 is slower, and I don't know what's the best way to add a flag
if there are more than 100 records.
Last, if possible, I would like to minimize entire table scans.