tags:

views:

64

answers:

3

Possible Duplicate:
SQL query with duplicate records

Hi.

I am trying to write a query to return rows from Customer table for multiple orders.

Currently I am writing 2 queries to solve this problem. Is there anyway I can put it in one query?

//Get all customers
select customerID from Customer 

//For each customer
select * from Orders where orderID in
      (select OrderId from Customer where customerID = 123456) 
                and success = 1

Here is the table structure

Customer table 
----------------------------------------- 
orderID          CustName      CustomerID 
--------------------------------------- 
100               test           123456     
101               test           123456 


Orders table 
------------------------------------ 
pID               OrderID      Success
----------------------------------- 
1                 100            1
2                 101            1
+1  A: 
select c.CustName, c.CustomerID, o.pID, o.OrderID
from Customer c
inner join Order o on c.orderID = o.OrderID
where o.Success = 1
RedFilter
A: 
select c.orderID, c.CustName, c.CustomerID, o.pID, o.OrderID, o.Success
FROM Customer c, Orders o
WHERE o.OrderID = c.orderID
bpeterson76
If you post code or XML, **please** highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it!
marc_s
A: 

Try this:

SELECT * FROM Orders JOIN Customers ON Orders.OrderID = Customers.orderID
Sam