Jump to content

MySQL search query


Jonob

Recommended Posts

I have a database table that stores imported information. For simplicity, its something like:

 

CREATE TABLE `data_import` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`payee` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `payee` (`payee`)
)

 

I also have a table that stores import rules:

 

CREATE TABLE `import_rules` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`search` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `search` (`search`)
)

 

The idea is that for each imported transaction, the query needs to try find a single matching rule - this match is done on the data_import.payee and import_rules.seach fields. There won't always be a match, and thats fine. Because these are both varchar fields, I have indexed them in the hope of making the query faster.

 

This is what I have come up with so far, which seems to work fine.

 

SELECT id.id, id.payee, ir.id, ir.search
FROM import_data id
LEFT JOIN import_rules ir on i.payee = ir.search

 

I would like to now make this search functionality a little bit more powerful, so that a partial match can be returned. Lets say, for example,

that we have id.payee = 'coca cola'  and ir.search = 'cola'. This should still return a match.

 

My understanding is that "LIKE '%search%'" has bad performance.

 

Are there any other alternatives?

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.