Hi,
Can anyone tell me if it is possible to combine the following two queries into one using a self-join and, if so, how to do it?
Query 1:
SELECT pm.username AS user,
uc.content_id AS id,
value AS filename,
name,
moderation_status AS status,
uc.parent_content_id
FROM myweb.ugc_meta um
LEFT JOIN myweb.ugc_content uc ON uc.content_id = um.item_id
LEFT JOIN myweb.userbase_member pm ON uc.user_id = pm.id
WHERE uc.content_type ='my.photo'
AND uc.promoted = '1'
AND moderation_status='passed'
LIMIT 10
Query 2:
SELECT value
FROM myweb.ugc_meta um
WHERE um.item_id = '4780c650137a3409901286'
-- (item_id is the content_parent_id from query 1)
ugc_meta
contains the album name for photos in ugc_content
. ugc_content
contains rows for albums AND photos. rows
representing photos have a parent_content_id
which is the content_id
for the parent row. I don't have the option of changing the table or DB structure.
At the moment I am running a new query (query2) for every result row from query 1 which is sub optimal ;-)
Thanks!