Professional Web Applications Themes

display neighboring records? - MySQL

My database looks like this: mysql> describe corpus; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | word | varchar(20) | YES | | NULL | | | tag | varchar(20) | YES | | NULL | | | lemma | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ Here's a section of it: | 11298 | de | NP | de | | 11299 | t?tulos | NP | <unknown> | | 11300 | e | SYM | ...

Sponsored Links
  1. #1

    Default display neighboring records?

    My database looks like this:

    mysql> describe corpus;
    +-------+-------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------+-------------+------+-----+---------+----------------+
    | ID | int(11) | NO | PRI | NULL | auto_increment |
    | word | varchar(20) | YES | | NULL | |
    | tag | varchar(20) | YES | | NULL | |
    | lemma | varchar(20) | YES | | NULL | |
    +-------+-------------+------+-----+---------+----------------+

    Here's a section of it:

    | 11298 | de | NP | de |
    | 11299 | t?tulos | NP | <unknown> |
    | 11300 | e | SYM | e |
    | 11301 | doentos | NNS | <unknown> |
    | 11302 | . | SENT | . |
    | 11303 | ? | SYM | ? |
    | 11304 | 2? | JJ | <unknown> |
    | 11305 | A | DT | a |
    | 11306 | conven??o | NN | <unknown> |
    | 11307 | somente | NN | <unknown> |
    | 11308 | obrigar? | NP | <unknown> |
    | 11309 | os | NN | os |
    | 11310 | filiados | NN | <unknown> |
    | 11311 | ?s | NNS | <unknown> |
    | 11312 | entidades | NNS | <unknown> |
    | 11313 | signat?rias | NNS | <unknown> |
    | 11314 | . | SENT | . |
    | 11315 | ? | SYM | ? |
    | 11316 | 3? | JJ | <unknown> |
    | 11317 | N?o | NP | <unknown> |
    | 11318 | se | FW | se |
    | 11319 | exime | NP | <unknown> |
    | 11320 | de | FW | de |
    | 11321 | prir | NN | <unknown> |
    | 11322 | a | DT | a |
    | 11323 | conven??o | NN | <unknown> |
    | 11324 | o | NN | o |
    | 11325 | fornecedor | NN | <unknown> |
    | 11326 | que | NP | que |
    | 11327 | se | FW | se |
    | 11328 | desligar | NP | <unknown> |
    | 11329 | da | NP | da |
    | 11330 | entidade | NN | <unknown> |
    | 11331 | em | NN | em |
    | 11332 | data | NNS | datum |
    | 11333 | posterior | JJ | posterior |
    | 11334 | ao | NN | <unknown> |
    | 11335 | registro | NN | <unknown> |
    | 11336 | do | VVP | do |
    | 11337 | instrumento | NN | <unknown> |
    | 11338 | . | SENT | . |


    I would like to search for word and for each word display word
    together with its 10 previous and its 10 subsequent records.

    For example, if word='de', a search in the previous section should
    return (lines added between hits):

    ------------------
    | 11298 | de | NP | de |
    | 11299 | t?tulos | NP | <unknown> |
    | 11300 | e | SYM | e |
    | 11301 | doentos | NNS | <unknown> |
    | 11302 | . | SENT | . |
    | 11303 | ? | SYM | ? |
    | 11304 | 2? | JJ | <unknown> |
    | 11305 | A | DT | a |
    | 11306 | conven??o | NN | <unknown> |
    | 11307 | somente | NN | <unknown> |
    ------------------
    | 11310 | filiados | NN | <unknown> |
    | 11311 | ?s | NNS | <unknown> |
    | 11312 | entidades | NNS | <unknown> |
    | 11313 | signat?rias | NNS | <unknown> |
    | 11314 | . | SENT | . |
    | 11315 | ? | SYM | ? |
    | 11316 | 3? | JJ | <unknown> |
    | 11317 | N?o | NP | <unknown> |
    | 11318 | se | FW | se |
    | 11319 | exime | NP | <unknown> |
    | 11320 | de | FW | de |
    | 11321 | prir | NN | <unknown> |
    | 11322 | a | DT | a |
    | 11323 | conven??o | NN | <unknown> |
    | 11324 | o | NN | o |
    | 11325 | fornecedor | NN | <unknown> |
    | 11326 | que | NP | que |
    | 11327 | se | FW | se |
    | 11328 | desligar | NP | <unknown> |
    | 11329 | da | NP | da |
    | 11330 | entidade | NN | <unknown> |
    ---------------------

    Thanks ahead for any help.

    bye
    tony

    Sponsored Links
    tonyberber Guest

  2. #2

    Default Re: display neighboring records?

    tonyberber a écrit : 

    try this:

    select T.*
    from T
    inner join
    (
    select t2.id
    from T t1
    inner join T t2
    on t1.word = 'de' <- what you search
    and t2.id between (t1.id - 9) and (t1.id + 9)
    group by t2.id
    ) X
    on T.id = X.id


    (where T is your table name)
    Zix.
    Zix Guest

  3. #3

    Default Re: display neighboring records?

    Look up the HANDLER statement in the doentation.

    Best regards,
    --
    Willem Bogaerts

    Application smith
    Kratz B.V.
    http://www.kratz.nl/
    Willem Guest

Similar Threads

  1. display records with a 0 count value
    By jhurst in forum MySQL
    Replies: 2
    Last Post: October 16th, 07:54 PM
  2. Records Display formatting
    By xcoldnet in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 25th, 11:00 PM
  3. Display Returned Records
    By Paulie579 in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: April 15th, 09:02 PM
  4. Air Brush Outline bleeds to the neighboring shape...
    By Ent0001 in forum Macromedia Fireworks
    Replies: 4
    Last Post: January 5th, 04:05 PM
  5. When records don't display that are there
    By Gerry in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 10th, 09:11 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139