Jump to content

joining 3 tables, one of which has multiple entries


Recommended Posts

MySql version 4.0.27 php version 4.4.4

 

cryptic huh.

 

I'm slow at this so please bear with me.  I don't even know what to call what I'm looking for, so if the answer is already on the forum, I apologise for repeating the question.

 

I have a table which contains a list of documents.  Each of these documents has key words, some documents have multiple keywords.  I have many documents and few keywords so I thought the best thing to do would be to create a table that held the keywords and join the two tables with a third table.

 

I want to print out the name of a document in a table with a table cell that contains the key words relevant to the document

 

Example

 

Doc Title 1 | keyword 1, Keyword 2 |

Doc Title 2 | keyword 1, Keyword 3 |

Doc Title 3 | keyword 2                |

 

I have a query which returns each document with the keywords associated with it, but it creates a new record for each entry so the results look like this:

 

Doc Title 1 | keyword 1 |

Doc Title 1 | keyword 2 |

Doc Title 2 | keyword 1 |

Doc Title 2 | keyword 3 |

 

Each record is unique because of the different keywords, but I only want the record to appear once and the associated keywords to appear seperated with a ','

 

This is my query:

 

SELECT * FROM tblDoc, tblKeyW, jnKwDoc

WHERE jnKwDoc.DocID = tblDoc.DocID

AND tblKeyW.KeyWID = jnKwDoc.KeyWID

 

the jnKwDoc holds a record containing each single keyword and the document ID.

 

I have no idea where to go from here.

 

 

Hello

 

thanks for that, but I really am a novice here and I don't understand which part of the query to use GROUP_CONCAT with in this query

 

SELECT * FROM tblDoc, tblKeyW, jnKwDoc

WHERE jnKwDoc.DocID = tblDoc.DocID

AND tblKeyW.KeyWID = jnKwDoc.KeyWID

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.