I have two different tables.One is file
and another one is image
. If uploaded content is image, then content details are stored in image table. Remaining(like doc,pdf etc) things are stored in file table. Both are identified by folder_id
.
Now I want to list both files and images according to given folder_id.
Exapmle:
image table
image_id description img_orig img_sm folder_id
1 Image one img_one.png img_one.png 1
2 Image_two img_two.png img_two.png 1
3 Image_three img_three.png img_three.png 2
File Table
file_id description file_name file_size folder_id file_type
1 file_one one.txt 11KB 1 text/plain
2 file_two two.html 2KB 1 text/html
Expected output table is
1 Image one img_one.png img_one.png 1 image
2 Image_two img_two.png img_two.png 1 image
1 file_one one.txt 11KB 1 text/plain
2 file_two two.html 2KB 1 text/html
I have tried UNION ALL
concept in MYSQL.
My snippet is
SELECT image_id as id,description,img_orig as name, img_sm as sm_size,folder_id,CONCAT('image','') as type
UNION ALL
SELECT folder_id as id,description,file_name as name, file_size as sm_size,folder_id,file_type as type
WHERE folder_id=1
It is working fine. But my question is have any another solution in this? Thanks in Advance.