Answer the question
In order to leave comments, you need to log in
Using a Variable as a List of Fields
I want to link 2 tables:
SELECT T1.id, <b>???</b>
FROM sc_user T1
INNER JOIN sc_user_value T2 ON T1.id_user = T2.id
WHERE T1.ID = 1
LIMIT 1;
SELECT GROUP_CONCAT(CONCAT('T2.', name) SEPARATOR '+" "+') AS name FROM sc_user_field WHERE use_as_name ORDER BY sort
Answer the question
In order to leave comments, you need to log in
No need to store a list of field names in another table.
It is necessary to read at least a primer on relational databases and learn how to use them humanly.
Never shift business logic to the database. A database is a place where data is stored, not processed. Then your applications will be dependent.
You thrust the 2nd request in under request of the first.
Get something like this.
Select t1.*,t2.*,t3.*
from t1
inner join t2 on t2.id=t1.t2id
inner join (select * from t3 ) as t3 on t3.id=t2.t3id
Throw off the structure of the tables, you will get an answer faster.
simplified model:
sc_user
id -> INT
sc_user_value
id -> INT
id_user -> INT (associated with sc_user.id)
user-added fields
sc_user_fields
name - CHAR (stores field name sc_user_value. user-added fields )
simplified model:
sc_user
id -> INT
sc_user_value
id -> INT
id_user -> INT (associated with sc_user.id)
user-added fields
sc_user_fields
name - CHAR (stores field name sc_user_value.user-added fields)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question