You can do this by turning your query into an aggregation using group by
:
select p.`prodid`,
sum(case when p.`desc` like 'Import/Export' then 100
when p.`desc` like 'Export' then 70
when p.`desc` like 'Import' then 50
else 20
end) as priority
from item i join
product p
on p.`prodid` = i.`prodid`
where p.`type` LIKE 'cleaning agent'
group by p.prodid;
Along the way, I fixed a few things:
- The
join
is now explicit in thefrom
clause, rather than implicit in thewhere
clause. - Because
i.prodid = p.prodid
, there is no need to include both in theselect
. - I changed the
case
statement to cascade. Only one of the conditions can match, so there is no reason to add things together. - I changed all the string constants to use single quotes rather than double quotes.