Answer the question
In order to leave comments, you need to log in
How to display data from two tables by a key field, in one table of which records with these keys are repeated?
The example1 table .
id, title, desc, key
Table example2 .
id, filename, key
There can be several files in the example2 table with the same key as in the example1 table. All problem that at "gluing" of tables, records repeat. That is, if we have three files, then the fields of the example1 table will be displayed three times, but filename will not be repeated.
I tried with GROUP BY, but the attempts are in vain.
SELECT * FROM example1 e1 INNER JOIN example2 e2 ON e1.key = e2.key GROUP BY ...
Answer the question
In order to leave comments, you need to log in
Maybe I misunderstood, but it looks like:
SELECT * FROM example1 e1 RIGHT JOIN example2 e2 ON e1.key = e2.key
If you print * then the records will not be repeated, because in the table "example2" at least the primary key will be different. Display in select only those fields that you need and choose the right expression in GROUP BY and nothing will be repeated.
Just written
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question