Using the following Customer, Country and Orders tables: Customer Table c_id c_name c_country_id 1 John 1 Country Table country_id Name 1 US 2 UK Orders Table o_id c_id Qty o_deliver_country_id 1 1 10 1 2 1 20 2

I need the following output in SQL

c_id c_name c_country_lives qty o_deliver_country

1 john US 10 US

2 john US 20 UK

Questions by Kallu1

Showing Answers 1 - 6 of 6 Answers

vishalb

  • Apr 25th, 2008
 

SELECT X.o_id, X.c_name,  X.[Name], X.qty , MT.[name] FROM

(SELECT OT.o_id, CT.c_name,  CUT.[Name], OT.qty , OT.o_deliver_country_id --CUT.o_deliver_country
FROM Orders OT Join Customer CT on OT.c_id=ct.c_id JOIN Country CUT on CT.C_country_id=CUT.country_id) AS x join Country MT on

X.o_deliver_country_id= MT.country_id

  Was this answer useful?  Yes

SELECT
  c.c_id,
  c.c_name ,
  ord.name AS "c_country_lives",
  ord.qty,
  ord.name AS "o_deliver_country"
FROM
  customer_c c,
  (SELECT *  
   FROM country ct,orders_o o
   WHERE   ct.country_id = o.o_deliver_country_id) ord   
WHERE c.c_id = ord.c_id;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions