S
S
sportik1742019-04-23 11:01:01
MySQL
sportik174, 2019-04-23 11:01:01

How to combine data from 2 mysql queries?

Good afternoon! I'm just learning MYSQL. Help me please.
The problem is this:
There are 2 tables (reviews, users)
If you query each table separately, the result looks something like this:
reviews: [
[0]: [
id: 1,
text: "Review text",
user_id: 5
],
[ 1]: [
id: 1,
text: "Review text 2",
user_id: 3
]
]
users: [
[0]: [
id: 5,
name: "Ivan",
surname: "Ivanov"
],
[1]: [
id: 3,
name: "Nicholas",
surname: "Nikolaev"
]
]
Is it possible to end up with something like this:
reviews: [
[0]: [
id: 1,
text: "Review text",
user_name: "Ivan"
user_surname: "Ivanov "
],
[1]: [
id: 1,
text: "Review text 2",
user_name: "Nikolai"
user_surname: "Nikolaev"
]
]
That is, to combine the data but at the same time so that the User's data is exactly the one whose ID is specified in the user_id field.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moses Fender, 2019-04-23
@sportik174

JOIN, LEFT JOIN, RIGHT JOIN are the most useful thing to recommend in this situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question