This is probably very basic, but I’m not experienced at all with sub selects.
I have two tables: prm_album and gallery_meta. prm_album stores name and id for each album, gallery_meta stores image details for every image of every album. The involved columns are thus:
prm_album: ID, Name gallery_meta: FileName, AlbumID, FileExt, IsDefault, Created
I’m trying to combine two queries – one gave me a list of albums, another gave me thumbnail info for each of those albums. I want to end up with a single array this time where I can get each album’s name, id, and it’s default (or first) image’s info.
SELECT a.ID, a.Abbr, a.Name, p.FileName, p.FileExt
FROM prm_album a
LEFT JOIN (
SELECT FileName, FileExt
FROM gallery_meta
ORDER BY (IsDefault = 1) DESC, Created ASC
LIMIT 0,1 ) AS p
ON (a.ID = p.AlbumID)
WHERE 1
When put through the console, this throws the error Unknown column 'p.AlbumID' in 'on clause'. All advice appreciated.
1 Answer