Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts

    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
    Last edited by BubikolRamios; 11-30-2012 at 10:55 PM.
    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •