Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-30-2012, 10:52 PM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
dig data from text

say I have table:

Code:
field1
bill
monica
...
and another table with text field, text field having large text files stored.

Any chance to get out something like this, using mysql, assuming one of text fields have text like that:
"....Bill gates is doing somethiing to monica lewinsky.... and monica lewinsky..."

expected result:

Code:
field1                      f
bill                      bill gates
monica                    monica lewinsky
monica                    monica lewinsky
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search

Last edited by BubikolRamios; 11-30-2012 at 10:55 PM..
BubikolRamios is offline   Reply With Quote
Old 11-30-2012, 11:16 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,217
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes. No. Sort of. For starters, you would only get "monica" once. You can only get one match out of a single record:
Code:
SELECT T1.field1, T2.f
FROM someTable AS T1, anotherTable AS T2
WHERE T2.f LIKE CONCAT('%',T1.field1,'%')
ORDER BY T1.field1
Also, how do you expect to get "bill gates" when the search term is just "bill"? Suppose the text said "....bill says that Bill of attainder is doing somethiing to monica lewinsky.... and monica lewinsky.."

That's going to find "bill" just the same as it would find "bill" in "bill gates".

In the above, would you expect then to find "bill of" or "bill of attainder" or "bill says" or????

You can only find what you search for.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 11-30-2012, 11:18 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,217
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Actual demonstration:
Code:
mysql> select * from t1;
+--------+
| f1     |
+--------+
| bill   |
| monica |
+--------+
2 rows in set (0.00 sec)

mysql> select * from t2;
+---------------------------------------------------------------------------------+
| f2                                                                              |
+---------------------------------------------------------------------------------+
| ....Bill gates is doing somethiing to monica lewinsky.... and monica lewinsky.. |
| bill says that bill of attainders are fon                                       |
+---------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> select * from t1,t2 where t2.f2 like concat('%',t1.f1,'%');
+--------+---------------------------------------------------------------------------------+
| f1     | f2                                                                              |
+--------+---------------------------------------------------------------------------------+
| bill   | ....Bill gates is doing somethiing to monica lewinsky.... and monica lewinsky.. |
| monica | ....Bill gates is doing somethiing to monica lewinsky.... and monica lewinsky.. |
| bill   | bill says that bill of attainders are fon                                       |
+--------+---------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 PM.


Advertisement
Log in to turn off these ads.