0

please read carefully because my english is not good, and the question has not an easy answer!

I have a simple structure like this:

table nodes
------------------------
nodeId | name       
     1 | Mazda Miata 2.0
     2 | Red Cars        
     3 | Mazda Cars 
     4 | Sport cars

table associations
------------------------
nodeId | hasNodeId
     1 | 2
     1 | 3
     1 | 4
     3 | 4
     3 | 1

and I want to select any row of the first table joining (in the same row) all the associated rows, according to what is specified by the table "associations"

the problem is that joining one node with one single node gives me the fulltext relevance of a SINGLE associated node: what I want is the relevance of ALL associated NODES

thank you

edit, the join result should be as you imagine like this, using the fulltext search:

nodeId | name                   | joinedName    |     fulltextRelev
     1 | Mazda Miata 2.0        | Red Cars      |     4.2
     1 | Mazda Miata 2.0        | Mazda Cars    |     2.3
     1 | Mazda Miata 2.0        | Sport Cars    |     3.2

the previous one is an abstract table, what i really want is to get unique/distinct nodeId, with the sum of the fulltextRelevance of the previous table... like this:

nodeId | name                   |     fulltextRelevSUM
     1 | Mazda Miata 2.0        |     9.7

9.7 = 4.2 + 2.3 + 3.2
7
  • I think it will be better to show at first your own issue resolve, or at least expected output
    – golgofa
    Apr 2, 2012 at 12:31
  • I don't know how to resolve, it is obvious that I cant join a row with a not-defined number of rows, but maybe with GROUP BY, or something like that, I can get the global fulltext relevance
    – skyline26
    Apr 2, 2012 at 12:38
  • 1 | Mazda Miata 2.0 | relevance 2.3 | "mazda" .... 1 | Mazda Miata 2.0 | relevance 4.4 | "red" etc... i want a single row that gives me relevance 2.3+4.4 because i want to do ORDER BY globalRelevance DESC
    – skyline26
    Apr 2, 2012 at 12:47
  • What is your desired output? please edit your question and put it there, this will help with alignment
    – GuZzie
    Apr 2, 2012 at 13:04
  • sorry for my lack of being clear... and for my english! edited the main question
    – skyline26
    Apr 2, 2012 at 13:15

2 Answers 2

1

You just have to group by your nodeId like this:

SELECT
nodeId, name, SUM(fulltextRelevSUM) AS fulltextRelevSum
FROM
/*your already done work here*/
GROUP BY nodeId
1
  • @toPeerOrNotToPeer what do you mean with "I can't get the sum"? show me your query
    – fancyPants
    Apr 3, 2012 at 7:53
0
    SELECT 
    n.nodeID,
    n.name,
    n2.name as joinedName,
    MATCH(n.name) AGAINST(n2.name) AS fulltextRelev
    FROM NODES n
    LEFT OUTER JOIN ASSOCIATIONS a
    ON n.nodeID = a.nodeID
    LEFT OUTER JOIN nodes n2
    ON n2.NODE_ID = a.hasNodeID
    WHERE n.nodeID = 1

I dont fully understand your text relevance part. can you explain it further? The above query will get you the desired first 4 rows, the query on the second part should be easy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.