join statement

From: Carl Forsman <fatwallet951_at_yahoo.com>
Date: Tue, 24 Feb 2009 23:03:18 -0800
Message-ID: <f9r9q4hhv2u4ers9v99mjrlv0h8enoq99v_at_4ax.com>



The following query will output 2 word that's close in position, but how can I output 3 word that's close in position instead of 2 word? the query will have 3 column output instead of 2 column output for words.

SELECT A.word As word1, B.word AS word2, A.document FROM Data AS A
JOIN Data AS B

   ON A.document = B.document
  AND A.position < B.position
  AND ABS(A.position - B.position) < 3;

Notes on Table and output:



I have a Table stores keywords + position of the word + document number 1 or 2 ... the word in.
Word	Position	Document
Great	1	1
Wall	2	1
China	3	1
Dog	3	2
Cat	7	2


===========================

I would like to output all word that are close related ... position of 2 word do not more than 3 word apart :

The output should be:
(Word1)(Word2)(Document#)

Great	Wall	1
Wall	China	1
Great	China	1
Received on Wed Feb 25 2009 - 01:03:18 CST

Original text of this message