shahid khan shahid khan - 3 months ago 8
MySQL Question

grouping based on same columid in mysql php

i am working on file uploading project in which file uploading was sucessful.

Now i am looking for displaying my uploads table which is used to store details of uploaded files is like:

+--------------------+--------------------+------------------+-----------+
| projectId | filename | projectDetails |ProjectName |
+--------------------+--------------------+------------------+------------+
| pid1 | admin.zip | This Is A Test |myProject |
| pid1 | admin1.zip | This Is A Test |myProject |
| pid2 | admin2.zip | This Is A Test2 |myProject2 |
| pid2 | admin3.zip | This Is A Test2 |myProject2 |
| pid1 | admin4.zip | This Is A Test |myProject |
+--------------------+--------------------+------------------+------------+


can i know that can i get an output like

+--------------------+--------------------+------------------+-----------+
| projectId | filename | projectDetails |ProjectName |
+--------------------+--------------------+------------------+------------+
| pid1 | admin.zip | This Is A Test |myProject |
| | admin1.zip | | |
| | admin4.zip | | |
+--------------------+--------------------+------------------+------------+

Answer

what about using this query :

select projectId, GROUP_CONCAT(distinct filename) as filename, projectDetails, ProjectName
from yourtable 
group by pid1
Comments