Jump to content

Comparing one column of db table against itself


franzy_pan

Recommended Posts

Hi,

 

I'm not too sure if this belongs in MySQL or PHP (depends on how it is to be accomplished).

 

What i need to be able to do is pull a field out of a database table and search against it to find like entires within itself ... say smoking and smokig (these are search terms generated by users so are likely to have typos hence why i need to be able to filter out like terms) once i have filtered out all the *duplicates* i then need to get it to show the occurence (amount of times it was used as a search) which should be relatively easy.

 

I'm just not too sure as to how to go about the initial search with the db table column comparing itself to itself.

 

Any ideas would be greatfully recieved - also if you need a better explanation let me know (its kinda hard to explain).

 

Thank you in advance  :D

 

 

Link to comment
Share on other sites

Put a better way is there a way for comparing mysql query output against itself (SELECT search_term FROM searches) ... checking search_term for like results, either through mysql or php?

 

i just need to be able to filter out results that are obviously very similar and therefore cut down the amount output when used for data processing by another system.

 

i'm not too sure how to go about starting this.

 

again any help would be great.

 

Thanks

Link to comment
Share on other sites

There will be a column of data (i.e. one field) in the database table, in this case search_terms ... i need to be able to find all the like terms within it to filter out the very similar to give one set of distinct search terms used.

 

I didn't explain it very well, but i need to find someway of limiting the results from that colum due to things like typos etc.

Link to comment
Share on other sites

Ok, i'm going for a slightly different approach to this and require a little help with my SQL.

 

Is there any way to get a limited number of results with a SELECT DISTINCT on only one field but using several in the query.  i.e. i need to be able to pull distinct search_terms out of the database only with several other fields like the user id, date and site.

 

Any help will be gratefully recieved.

 

Thanks

Link to comment
Share on other sites

Data

   term
+---------+
' smoking '
' smokig  '
' boots   '
' botts   '
' widgets '
' widegts '

 

Query

SELECT a.term, b.term FROM item a
INNER JOIN item b
ON SOUNDEX(a.term) = SOUNDEX(b.term)
WHERE a.term > b.term

 

Results

   a.term      b.term
+-----------+----------+
'  botts    ' boots    '
'  widgets  ' widegts  '

 

Unfortunately it pulled all but your smoking/smokig example :(

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.