Hi Sir One Of the Interviewer asked this question like ---- 1Q: You have a microsoft SQL server database that contains tables customers & Orders .The tables are related with a --Column named CustomerId .You need to create a query that meet a following requirements: --Returns the Customername for all Customers and the Orderdate for any orders that they have placed. --Results must include customers who have not placed any order ? 2Q: Update tables on Table A wherever it is empty from table B by using id? /* Table A Table B Id Name Id Name 1 ABC 1 John 2 2 Kim 3 GHI 3 Riyan */ will u please make a video for this .
question 2 we should use merge MERGE tabA AS TARGET USING tabB AS SOURCE ON SOURCE.id1 = TARGET.id2 WHEN MATCHED THEN UPDATE SET TARGET.name = coalesce(target.name , SOURCE.name)
i didnt understand 1st question . it says to get those customers who made an order . it must not include those customers woh didn''t place any order. select c.customer_name , o.orderdate from customers c inner join orders o on c.customerid = o.order_id the above query will work. bcoz if a customer id 2 is present in customer table but not present in orders table then cusstomer id 2 has not placed an order . so if we do inner join we will get the customer id who are in customer and orders table
Thanks lot
Most welcome
Hi Sir One Of the Interviewer asked this question like ---- 1Q: You have a microsoft SQL server database that contains tables customers & Orders .The tables are related with a
--Column named CustomerId .You need to create a query that meet a following requirements:
--Returns the Customername for all Customers and the Orderdate for any orders that they have placed.
--Results must include customers who have not placed any order ?
2Q: Update tables on Table A wherever it is empty from table B by using id?
/* Table A Table B
Id Name Id Name
1 ABC 1 John
2 2 Kim
3 GHI 3 Riyan
*/
will u please make a video for this .
question 2 we should use merge
MERGE tabA AS TARGET USING tabB AS SOURCE
ON SOURCE.id1 = TARGET.id2
WHEN MATCHED
THEN UPDATE
SET TARGET.name = coalesce(target.name , SOURCE.name)
i didnt understand 1st question .
it says to get those customers who made an order . it must not include those customers woh didn''t place any order.
select c.customer_name , o.orderdate from customers c
inner join orders o
on c.customerid = o.order_id
the above query will work.
bcoz if a customer id 2 is present in customer table but not present in orders table then cusstomer id 2 has not placed an order .
so if we do inner join we will get the customer id who are in customer and orders table