I am trying to do two multiple left joins AND two more left joins where I only want the first result of each of those two returned
so this is the base query which works fine:
SELECT casestuds.cs_id AS curcs, serv_names.item_name AS servname,
serv_names.item_id AS servid, clients.item_name AS cliname, piclib.pic_name AS pic_hi_name
FROM casestuds
LEFT JOIN serv_names ON (casestuds.cs_serv=serv_names.item_id)
LEFT JOIN clients ON (clients.item_id=casestuds.cs_cli)
LEFT JOIN piclib ON (casestuds.cs_id=piclib.cs_id AND piclib.pic_hilite='1')
WHERE cs_shw='1'
ORDER BY cliname
now I want to left join two more tables "sct_match" and "spac_match" which might have 0 to several matches for each main item but I only want the first one it finds
so this kind of works:
SELECT casestuds.cs_id AS curcs, serv_names.item_name AS servname,
serv_names.item_id AS servid, clients.item_name AS cliname, piclib.pic_name AS pic_hi_name
FROM casestuds
LEFT JOIN serv_names ON (casestuds.cs_serv=serv_names.item_id)
LEFT JOIN sct_match ON (casestuds.cs_id=sct_match.cs_id)
LEFT JOIN spac_match ON (casestuds.cs_id=spac_match.cs_id )
LEFT JOIN clients ON (clients.item_id=casestuds.cs_cli)
LEFT JOIN piclib ON (casestuds.cs_id=piclib.cs_id AND piclib.pic_hilite='1')
WHERE cs_shw='1' AND sct_match.item_id='12'
ORDER BY cliname
but if the category I am not searching on has several matches it returns the item that number of times, which I understand - but I only want to see it once
not sure how to approach this, any help much appreciated
thanks