I have this data from a xml file:
<?xml version="1.0" encoding="utf-8" ?>
<words>
<id>...</id>
<word>...</word>
<meaning>...</meaning>
<translation>
<ES>...</ES>
<PT>...</PT>
</translation>
</words>
This forms the table named “words”, which has four fields (“id”,”word”,”meaning” and “translation”). On the other hand, the “translation” field can hold several languages like ES,PT,EN,JA,KO,etc… So I create a table (“words.translation”, one field is “id” and the others ones are languages ids like “ES”,”PT”,…).
I’m sorry for this newby question, but I’d like to know a couple of things about this one-to-many relationship.
- How to join (or link?) this two tables in MySQL?
- What information does the “translation” field in the “words” table has to store?
- How is the sql query to get all the word information (JOIN syntax used?)
Thanks for your patience.
I’ll try to answer …
You can link the two tables by declaring a foreign key constraint between the ‘word_id’ in the TRANSLATION table and the ‘id’ field in in the WORD table.
since there are many translations and only one ‘original’ word in the design you propose, the link will be from translation (many) to word (one), the link is the ‘word_id’ I mentioned under 1.
Please note that a different design with only one single table that contains ‘word,meaning,language’ and a meaning_id to self-join translations, might be better for words with multiple translations/meanings.
assuming two tables, word and translation, the syntax would be
caveat: your design assumes that there will always be a on to one translation from one language to another. Un?-fortunately that is not true.
Each word has a set of co-meanings that differ from language to language, your meaning field implies that you are aware of this.
Table WORD: id | word | meaning
PK on word_id
Table TRANSLATION word_id | language | word
PK on (word_id,language), FK word_id -> WORD