I
I
Ilya Bobkov2016-01-05 13:39:08
MySQL
Ilya Bobkov, 2016-01-05 13:39:08

How to make a sample?

Hello. I had such task:
There is a table users:
id | fio | val1 | val2 | val3 |
----------------------------------------------------- |
0 | ivanov | 0 | 1 | 3 |
------------------------------------------------
In the fields val id values ​​from another table values:
id | values ​​|
----------------------
0 100
1 200
2 300
---------------------- -
What query do you need to execute so that you return the first table with the values ​​from the second?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romy4, 2016-01-05
@romy4

query with JOIN

D
Djadka Maxho, 2016-01-05
@Djadka

Attention pseudocode

SELECT `id`, `fio`,  `v1`.`values` AS `val1`, `v2`.`values` AS `val2`, `v3`.`values` AS `val3`  
FROM `users` AS `u`
JOIN `values` AS `v1` ON `u`.`val1` = `v1`.`id`
JOIN `values` AS `v2` ON `u`.`val2` = `v2`.`id`
JOIN `values` AS `v3` ON `u`.`val3` = `v3`.`id`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question