|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I'm needing to make a list of all customers in my database who have not purchased anything. I can't seem to think of any way but a subquery (not yet implimented) to make this work.
I have the two queries: 1. SELECT DISTINCT custid from customers 2. SELECT DISTINCT custid from orders WHERE subtot > 0 and !voided I basically need the difference of the two. Thanks in advance. |
|
#2
|
|||
|
|||
|
You'll have to do two queries since mysql does not support sub queries.
If you are using PHP you can do this: $result=mysql_query("select distinct custid from orders where subtot>0 and !voided"); while (list($data[])=mysql_fetch_row($result)){} $listed_ids=implode(',',$data); $result2=mysql_query("select distinct custid from customers where custid !(in('$listed_ids'))"); while (list($nosales[])=mysql_fetch_row($result2){} This will return the array $nosales containing the custids that have no sales. |
|
#3
|
|||
|
|||
|
You may be able to get by with a LEFT JOIN, but since I don't know the layout of your tables, this may be a shot in the dark
> select customers.custid > from customers > LEFT JOIN orders on customers.custid=orders.custid > WHERE orders.custid IS NULL; |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Workaround for mySQL subquery? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|