hello all i have to join two queries to form an result set :-
1st:
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId
FROM
ecart_product
INNER JOIN ecart_orderdetail
WHERE
ecart_orderdetail.productId = ecart_product.id
group by orderId
this gives me
orderId catId 167 59, 2 168 2 169 2 170 2 171 2 172 48, 2 173 2 174 2
2nd:
select * from ecart_orders
in both orderId is common how could this could be join ?
In mean time i also solved it
select * from ecart_orders Inner join(
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId
FROM `ecart_product` INNER JOIN ecart_orderdetail
WHERE ecart_orderdetail.productId = ecart_product.id group by orderId) as c
on ecart_orders.id=c.orderId
Assuming that orderId
is PK in ecart_orders
table and that it has productId
column.
You can try this:
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId ,
ecart_orders.*
FROM
ecart_product
INNER JOIN ecart_orderdetail
ON ecart_orderdetail.productId = ecart_product.id
INNER JOIN ecart_orders
ON ecart_orders.productId = ecart_product.id
group by orderId