In this article we would be fetching similar records with lookup details.
Consider a retailer needs to know similar order placed along with the customer information.
There are two tables Order and Customer, the SQL query goes like this:
select c.customer_name, c.customer_location, co.brand, co.item_type, co.item_domain, co.item_manufacturer from customer c
inner join (
select o.brand_id, o.brand_id, o.brand_name, o.item_type, o.item_domain, o.item.manufacturer , o.customer_id, from Order o
where o.domain='mobile'
group by o.brand, o.item_type, o.item_domain, o.item.manufacturer
HAVING
COUNT(o. brand_id) > 1
) co on co. customer_id=c. customer_id;
No comments:
Post a Comment