Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT RETURNING MULTIPLE ROWS

Status
Not open for further replies.

puma51

IS-IT--Management
Sep 27, 2006
10
0
0
GB
Hi

I am trying to do an insert into a table but it is returning multiple rows.

The source table contains the following:-

Plan_No, Plan_Date, Company_No, User_No
123456, 01/01/2007, 456, 5
543454, 07/02/2007, 456, 4
345654, 21/03/2007, 456, 5

My select is as follows:

insert into MIN_PLANDATE
select COMPANY_NO,min(PLAN_DATE), min(PLAN_NO), USER_NO
FROM PLANS
WHERE (company_no NOT IN (0,96862,98888))
and PLAN_DATE BETWEEN '01-Apr-2006' and sysdate
and not company_no is null
group by COMPANY_NO, PLAN_DATE, PLAN_NO, USER_NO;

I only want it to insert the row with the minimum plan_date once but it is inserting it 3 times because there are 3 plans.

Can anyone help me with this please.

Many thanks

puma
 
Use the standard sub-query method to restrict your choice to the MIN date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top