0

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.

  1. I have to fetch details of a customer along with items ordered by that customer.
  2. The shipping details of the particular order of customer named ‘X’
  3. The total order amount on ’a random date here’ for customer ‘X’

Thanks

2
  • You can use data from multiple tables by using "Join" Commented Apr 15, 2021 at 6:24
  • Thank you..but I don't know how this JOIN works. Perhaps It would be very tough for me to handle both software and database at same time.. Commented Apr 15, 2021 at 6:25

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

4 Comments

@GoruChagol i've just updated the answer. Please check !
I have a query. cid and cname are different. here, X represents cname. not cid. Pardon me, If I could not make u understand at first. Please help.
@GoruChagol Oh ok my bad :). So basically you need to join Customer table for on Cid and make query condition with where cname = 'X'. Check update plz
@GoruChagol hope it worked, then you can accept the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.