List:General Discussion« Previous MessageNext Message »
From:Jerry Schwartz Date:October 23 2006 1:23pm
Subject:RE: help with query: select customers that ARO NOT in orders table
View as plain text  
Is a sub-select more efficient than an outer join?

SELECT cust_id FROM customers LEFT JOIN orders on customers.cust_id =
  orders.cust_id WHERE orders.cust_id IS NULL;

Or am I missing something (as usual)?

Regards,

Jerry Schwartz
Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341


> -----Original Message-----
> From: Waldemar Jankowski [mailto:waldemar@stripped]
> Sent: Friday, October 20, 2006 1:53 PM
> To: afan@stripped
> Cc: mysql@stripped
> Subject: Re: help with query: select customers that ARO NOT
> in orders table
>
> On Fri, 20 Oct 2006, afan@stripped wrote:
>
> > hi to all,
> > I have table customers (PK cust_id)
> > I have table orders (PK order_id, FK cust_id)
> >
> > I need query that will selecct all customers from
> 'customers' they don't
> > have any order, there is not their cust_id in 'orders'.
> >
> > couls somebody help me?
> >
> > thanks.
> >
> > -afan
>
> I think the most explicit way is with a sub select:
>
> select cust_id from customers where
> cust_id not in
>  	(select cust_id from orders);
>
> -w
>
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> http://lists.mysql.com/mysql?unsub=1
> >
> >
> >
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=1
>
>



Thread
help with query: select customers that ARO NOT in orders tableafan20 Oct
  • Re: help with query: select customers that ARO NOT in orders tableWaldemar Jankowski20 Oct
    • Re: help with query: select customers that ARO NOT in orders tableafan20 Oct
      • Re: help with query: select customers that ARO NOT in orders tableWaldemar Jankowski20 Oct
    • RE: help with query: select customers that ARO NOT in orders tableJerry Schwartz23 Oct
      • RE: help with query: select customers that ARO NOT in orders tWaldemar Jankowski23 Oct