php - mysql Column name change using join
Get the solution ↓↓↓Solution:
i dont understand... if you want to rename the column names you can useAS
SELECT f1 AS "field_name1", f2 AS "field_name2", f3 AS "field_name3" FROM table
EDIT:
try something like this:
SELECT f1,f2,f3,f4...
FROM data_table
LEFT JOIN data_table ON data_table.f1=(SELECT field_name FROM fields_names WHERE a_flag='f1') AND data_table.f2=(SELECT field_name FROM fields_names WHERE a_flag='f2')
Answer
Solution:
It sounds like you might want to do something like this:
select d_id,
max(case when field_name = 'Header' then value end) Header,
max(case when field_name = 'ID No.' then value end) ID_No,
max(case when field_name = 'Image' then value end) Image,
max(case when field_name = 'Name' then value end) Name
from
(
select d_id, f1 value, 'f1' col
from data_table
union all
select d_id, f2 value, 'f2' col
from data_table
union all
select d_id, f3 value, 'f3' col
from data_table
union all
select d_id, f4 value, 'f4' col
from data_table
) u
inner join fields_name f
on u.col = f.a_flag
group by d_id
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: videoxxx
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.