Reputation: 13
I have the following tables which are represented in form of schema :
Customer (cid, cname, mobile, address, gender, email)
Orders (order_no, company_name, order_date, cid, item_id, quantity)
Items (item_id, item_name, unit_price)
E_company (company_name, address, mobile)
Shipping (sid, cid, company_name, order_no, ship_date)
The problem is I don't know how can I search data from multiple tables and represent it in my software interface. Although I can represent it but I can't retrieve the data from the tables. So, here are the required data i needed to fetch.
Thanks
Upvotes: 0
Views: 164
Reputation: 249
For example with those 2 tables :
Customer (cid, cname, mobile, address, gender, email)
Orders (order_no, company_name, order_date, cid, item_id, quantity)
You can write query like this to "fetch details of a customer along with items ordered by that customer"
Select C.*, O.* from Customer C
Left join Orders O
On C.cid = O.cid
"The shipping details of the particular order of customer named ‘X’"
Select * from Shipping S
left join Customer C
on S.cid = C.cid
and C.cname = 'X'
"The total order amount on ’a random date here’ for customer ‘X’"
Select sum(quantity)
From Orders O
Left join Customer C
On O.cid = C.cid
Where O.order_date = 'random_date' and C.cname = 'X'
Upvotes: 1