In MySQL kunt u substring_index()
. gebruiken en aggregatie:
select o.quoteId, o.salesorderid,
max(q.quote_id)
from orders o left join
quotes q
on o.quoteId = substring_index(q.quoteId, '-', 1)
group by o.quoteId;
In SQL Server (of ook MySQL) kunt u LIKE
. gebruiken voor de vergelijking:
select o.quoteId, o.salesorderid,
max(q.quote_id)
from orders o left join
quotes q
on q.quoteId like concat(o.quoteId, '-%')
group by o.quoteId;