SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    table2 record its value belongs to a record in table1

    data in myTable1

    (table1_ID) sentence

    (1) I am a boy
    (2) She is a girl

    data in myTable2

    (table2_ID) word

    (1) She
    (2) am
    (3) girl
    (4) boy
    (5) a
    (6) I
    (7) is
    I have two tables like the above.
    And the code below will produce the result below.

    Code:
    code1
    select sentence
    from myTable1
    where table1_ID = 1
    
    result1
    (1) I am a boy
    
    code2
    select sentence
    from myTable1
    where table1_ID = 2
    
    result2
    (2) She is a girl
    I like to produce the target result like the below.
    The would-be codes below doesn't work correctly, but it will tell you what I am trying to do.

    woud-be code with "1"

    select table2_ID, word
    from myTable1, myTable2
    where '%word%' belong to 'sentence' and table1_ID=1

    target result 1
    (2) am
    (4) boy
    (5) a
    (6) I

    would-be code with "2"

    select table2_ID, word
    from myTable1, myTable2
    where '%word%' belong to 'sentence' and table1_ID=2

    target result 2

    (1) She
    (3) girl
    (5) a
    (7) is
    Can I produce my target result with your help?

    Thanks in Advance
    Last edited by dotJoon; Nov 26, 2004 at 02:42.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Miami, Florida - Caracas, Venezuela
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you list the columns for each table? You are listing the values but I'm confused as to what your columns are.

    I think what you are trying to achieve can be done using

    [qoute]expr LIKE '%word%'[/qoute]

    You can find more info here: http://dev.mysql.com/doc/mysql/en/St...functions.html

    Hope this helps.
    Luis

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lgomez
    Could you list the columns for each table? You are listing the values but I'm confused as to what your columns are.

    There are two columns(table1_ID, sentence) in myTable1.
    And there are also two comumns(table2_ID, word) in myTable2.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select table2_ID
         , word
      from myTable1
         , myTable2
     where table1_ID = 2
       and concat(' ',sentence,' ')
      like concat('% ',word,' %')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much.


Bookmarks

Posting Permissions

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