Jump to content

MATCH() returning empty set


soycharliente

Recommended Posts

I've never used match() before and I don't know what I'm missing. I'm trying to make a basic search input box on the homepage. Return results that match the input in either the firstname or lastname. Not exact matches. Could be contained within a longer string.

 

SELECT * FROM `users`
WHERE MATCH (`firstname`,`lastname`) AGAINST ('John' IN BOOLEAN MODE)
ORDER BY `lastname` ASC, `firstname` ASC

 

I'm getting an empty set with dummy data consisting of many john, johnson, johnny, etc. in both firstname and lastname.

 

Any help or a reference to example that better explains? I don't find the MySQL entry on match() very helpful AT ALL.

 

Thanks.

Link to comment
Share on other sites

I even tried using LIKE. However, I am finding that it is completely case sensitive even though the manual explicitly says it's not.

 

SELECT * FROM `users`
WHERE `firstname` LIKE '%Smith%' OR `lastname` LIKE '%Smith%'
ORDER BY `lastname` ASC, `firstname` ASC

 

That returns John Smith but not John Blacksmith. And if I change to lowercase, it switches the returned result.

Link to comment
Share on other sites

I figured out I could do this.

 

SELECT * FROM `users`
WHERE UPPER(`firstname`) LIKE UPPER('%blah%')
OR UPPER(`lastname`) LIKE UPPER('%blah%')
ORDER BY `lastname` ASC, `firstname` ASC

 

If anyone ends up being able to help me, please post. I'm going to move forward with this since it's working. Not really happy about doing this, but maybe it's the only way.

Link to comment
Share on other sites

CREATE TABLE IF NOT EXISTS `users` (
  `id` int( NOT NULL auto_increment,
  `eid` int(9) NOT NULL,
  `firstname` varchar(64) collate utf8_bin NOT NULL,
  `lastname` varchar(64) collate utf8_bin NOT NULL,
  `email` varchar(255) collate utf8_bin default NULL,
  `address` varchar(64) collate utf8_bin default NULL,
  `city` varchar(64) collate utf8_bin default NULL,
  `state` varchar(4) collate utf8_bin default NULL,
  `zip` varchar(16) collate utf8_bin default NULL,
  `phone` varchar(16) collate utf8_bin default NULL,
  `gender` enum('M','F') collate utf8_bin default NULL,
  `ethnicity` varchar(255) collate utf8_bin default NULL
  PRIMARY KEY  (`id`),
  UNIQUE KEY `eid` (`eid`)
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.