0

I have this table in my db

id | major | code_lesson | files

Which the contents look like this

id | major | code_lesson | files
1  | Math  | MAT12       | mat.pdf
2  | Socio | SOC15       | soc.pdf
3  | Math  | MAT12       | mat_pre.pdf
4  | Physic| PHY19       | physci.pdf
5  | Physic| PHY19       | phy2.pdf

I want to display this table like this

major |file1       |file2
Math  |mat.pdf     |math_pre.pdf
Socio |soc.pdf     |
Physic|physci.pdf  |phy2.pdf

Can you please explain me how to achieve this, since my output result 1 rows :

select major, files as file1, (select files where max(id)) as file2 from db_school

Thanks in advance

1
  • User can insert record only two files with the same major Commented Aug 13, 2019 at 15:17

1 Answer 1

0

user can insert record only two files with the same major

SELECT t1.major, t1.files file1, t2.files file2
FROM db_school t1
LEFT JOIN db_school t2 ON t1.major = t2.major
                      AND t1.id < t2.id
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.