If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Subquery

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-04, 10:17
Jen76 Jen76 is offline
Registered User
 
Join Date: Jan 2004
Location: California
Posts: 10
Subquery

My Query:

INSERT INTO Item_Billing_Link (Product_ID) SELECT Products.Product_ID FROM Products WHERE Products.Recurring = "yes" AND Products.Cust_ID = (SELECT Customers.Cust_ID FROM Customers WHERE Customers.Bill_Cycle_ID = "1");


Problem:

Failed to execute SQL : SQL INSERT INTO Item_Billing_Link (Product_ID) SELECT Products.Product_ID FROM Products WHERE Products.Recurring = "yes" AND Products.Cust_ID = (SELECT Customers.Cust_ID FROM Customers WHERE Customers.Bill_Cycle_ID = "1") failed : Subquery returns more than 1 row

Help!
Reply With Quote
  #2 (permalink)  
Old 03-01-04, 04:06
calum433 calum433 is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen
Posts: 12
Hi,

I'd say the subquery it doesn't like is the

AND Products.Cust_ID = (SELECT Customers.Cust_ID FROM Customers WHERE Customers.Bill_Cycle_ID = "1")

bit. It's likely that this select returns more than one value so what you are saying is something like -

AND Products.Cust_ID = (1,10,12,15,19,32,etc)

You instead want to achieve something like

AND Products.Cust_ID IN (1,10,12,etc)
__________________
Calum
www.4-3-3.com
Online football Management Game
Reply With Quote
  #3 (permalink)  
Old 03-01-04, 05:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
PHP Code:
insert 
  into Item_Billing_Link 
(Product_ID
select distinct
       Products
.Product_ID 
  from Products 
inner
  join Customers  
    on Products
.Cust_ID Customers.Cust_ID
 where Products
.Recurring 'yes' 
   
and Customers.Bill_Cycle_ID 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On