A
A
Andrey Kolesnik2020-10-01 21:44:32
SQL
Andrey Kolesnik, 2020-10-01 21:44:32

Output from two sql tables?

Do not judge strictly, my first question (I used to find the answer myself)
There is a table 'massages' and 'users'
I could link the tables, but ...
It is necessary that instead of the number (id of the sms sender) the name of this person is displayed.
example
I - my id = 1
in the id_sender column (in the 'massages' table) it is written like that.
it is necessary that instead of this id the username (of this id) from the users table is displayed.
Below are pictures of the database and the sql code
"SELECT
u.*,
m.*
FROM
users AS u,
messages AS m
WHERE
u.id = m.id_sms
");
And yes. i don't want to use PDO
5f76233d84648323455804.png
5f7621b41c4d4531309055.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Gnevyshev, 2020-10-01
@chikada3301

As an option:

SELECT m.id_sms, u.name as id_sender, m.message, m.id_recipient
FROM messages m
LEFT JOIN users u ON m.id_sender = u.id
ORDER BY m.id_sms DESC
LIMIT 100

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question