E
E
Evgeny Kramor2018-05-26 22:01:12
SQL
Evgeny Kramor, 2018-05-26 22:01:12

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 ...

Can you please tell me how to make a request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2018-05-26
@usdglander

Maybe I misunderstood, but it looks like:

SELECT * FROM example1 e1 RIGHT JOIN example2 e2 ON e1.key = e2.key

V
Vladimir, 2018-05-26
@Casufi

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 question

Ask a Question

731 491 924 answers to any question