M
M
Mir2017-09-01 08:45:58
PHP
Mir, 2017-09-01 08:45:58

How to add data from the first table with data from the second table in one mysql query?

There are two tables
item
id | name | color
1 | orange | yellow
2 | Apple | red
3 | Pear | green
photo
id | id_item | name_file_jpg
1 | 1 | wauhmaifml2
| 1 | wmacawowa
3 | 1 | mdv21kmzxi
4 | 2 | wauhawffml
5 | 3 | nalwfjnawfb
6 | 3 | cijxx9pb8jxa
How can I get the full output of the first item table from these tables and, in addition, only the first record of the name_file_jpg field from the second table?
That is, something in the style of
id | name | color | name_file_jpg
1 | orange | yellow | wauhmaifml
2 | Apple | red | wauhawffml
3 | Pear | green | nalwfjnawfb

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mir, 2017-09-01
@mir546

Googled badly.
Need to do it like this

SELECT id, name, color, name_file_jpg FROM item, photo  WHERE id_item = id GROUP BY id;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question