K
K
Konstantin Malyarov2016-06-25 23:09:27
MySQL
Konstantin Malyarov, 2016-06-25 23:09:27

How to pull string value through int in related tables?

There is a users table :

id_user: 1
username(var): root
password(var): root
role(int): 1
department(int): 1

role table :
id_role: 1
role: admin

department table :
id_department: 1
department: all

How to get string value from related table at once?
On request:
select role from users where username="root" and password = "root";

I will get the id, how to get not the id, but the value right away?
role = session.createQuery("Какой запрос сюда ставить?").toString();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Yakovenko, 2016-06-25
@Konstantin18ko

LEFT JOIN

SELECT role.role FROM users LEFT JOIN role ON users.role=role.id WHERE users.username="root" AND users.password = "root";
Should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question