home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases
- Path: sparky!uunet!gatech!darwin.sura.net!newsserver.jvnc.net!newsserver.technet.sg!nuscc!CHANHC@iscs.nus.sg
- From: chanhc@iscs.nus.sg
- Subject: Re: Help with SQL statement
- Message-ID: <1993Jan26.014419.4051@nuscc.nus.sg>
- Sender: usenet@nuscc.nus.sg
- Reply-To: CHANHC@NUSDISCS.BITNET
- Organization: Dept. of Information Systems and Computer Science, National University of Singapore
- References: <1993Jan22.211051.4867@vpnet.chi.il.us>
- Distribution: na
- Date: Tue, 26 Jan 1993 01:44:19 GMT
- Lines: 33
-
- In article <1993Jan22.211051.4867@vpnet.chi.il.us>, mike@vpnet.chi.il.us
- (michael kamlet) writes:
- >I'm having a problem writing an SQL statement for the following situation
- >(and I'm not sure its really possible)
- >
- >I have 2 tables lets say I have a Customer table and an order table.
- >I want to query the database for all customers and show their orders
- >for the past month. I may have more than 1 order for a customer.
- >
- >The problem is that if I don't have an order for a customer, the join will
- >not find a match and that customer will be left out of the report.
- >
- >I still want to show the customer even if no orders are present.
- >
- >Is this possible with SQL ?? was my explanation clear enough ??
- >
- >Thanks
- >
- > Mike Kamlet
- > mike@vpnet.chi.il.us
- You need to union the normal answer with the answer from a query
- that finds the customers with no orders, e.g.
- select cust_num, cust_name, order_num, order_item
- from customer, order
- where cust_num = order.cnum
- union
- select cust_num, cust_name, ' ', ' '
- from customer
- where not exists (select order_num
- from order
- where order.cnum = cust_num)
-
- >
-