E
E
Erl2018-09-20 11:58:32
MySQL
Erl, 2018-09-20 11:58:32

How to get field name from linked table?

Good day, I’m incredibly stupid in this matter.
There are 2 tables:
1) users
2) consts
and in that one there is a const_id by which they are connected, that is, in the users table, respectively, only const_id is output;
in the const table, all parameters for the user are stored as minimum name, etc.
when displaying data in foreach from the users table, I would like to display not const_id, but its name

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Letyagin, 2018-09-20
@NooBiToo

SELECT users.*, const.name FROM users
LEFT JOIN const ON users.const_id = const.id

Well, you can not forget that the fields can be given their own names
SELECT users.*, const.name const_name FROM users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question