S
S
sunnyrio2018-06-21 13:16:03
MySQL
sunnyrio, 2018-06-21 13:16:03

How to replace table id with names from other table?

There is a table logs (id, product_id, count, user_id, status)
How to organize a query to replace product_id with names from the products(id, name) table, and user_id with names from the user(id, name) table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Starkov, 2018-06-21
@sunnyrio

SELECT products.name AS product_name, user.name AS user_name
FROM logs
LEFT JOIN products ON products.id = logs.product_id
LEFT JOIN user ON user.id = logs.user_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question