I
I
Ivan2015-09-10 12:35:24
MySQL
Ivan, 2015-09-10 12:35:24

How to get multiple values ​​from an attached table?

The title is a little chaotic, I don't know how to phrase it better.
So, there are, in a simple version, 2 tables connected by a many-to-many association:
USERS

id | username
1  | Арнольд
2  | Сильвестр

SUBJECTS
id | title
1  | Математика
2  | Физика

USERS_SUBJECTS
user_id | subject_id
1       | 1
1       | 2
2       | 1

Something like this returns, respectively, only one result from USERS_SUBJECTS (well, it's stupid to expect another):
SELECT users.id, users.username, users_subjects.subject_id AS sid FROM users
    LEFT JOIN users_subjects ON users_subjects.user_id
GROUP BY users.id /*эта штука мне нужна*/

Actually, for each user, I need a list of items to which he is attached. And in the most ideal case, it would be one result (i.e. Arnold, who is strong in both physics and mathematics, was issued in one line with a list of subjects).
The difficulty is that the structure (and the general query) is more complicated than described here and all sorts, limits, offsets and other group by are needed.
Or, if this is not possible, how to get information for user lists in such cases?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
murrometz, 2015-09-10
@xShimmy

Look for join concat mysql

L
LittleFatNinja, 2015-09-10
@LittleFatNinja

How to get multiple values ​​from JOIN?

JOIN is an operator. no value can be obtained from it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question