I have 2 mysql tables,
1st table holds data about files (including a folder id)
2nd table holds data about folders
I want to select the files per user, and i also need to include the folder name, which is held in the second table.
So i need to join these tables somehow.
table 1 - files
`file_id` int(20) NOT NULL AUTO_INCREMENT,
`FILE_NAME` varchar(200) NOT NULL,
`FILE_SIZE` varchar(200) NOT NULL,
`FILE_TYPE` varchar(200) NOT NULL,
`file_added` datetime DEFAULT NULL,
`share_type` varchar(200) NOT NULL,
`folder_id` int(20) NOT NULL,
`u_id` int(11) NOT NULL,
table 2 - folders
`folder_id` int(20) NOT NULL AUTO_INCREMENT,
`folder_name` varchar(200) NOT NULL,
`u_id` int(11) NOT NULL,
So i need to be able to select: file_name(table1), file_size(table1), folder_name(table2)
I've tried a lot of things, like this foe example:
SELECT files.file_name, files.file_size, folders.folder_name
FROM files
JOIN folders ON files.u_id = folders.u_id
WHERE
files.u_id = ?
AND folders.u_id = ?
ORDER BY folders.folder_name, files.file_name
but that just returns multiple rows of the files with each folder name at the end
How far wrong am i?