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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp table of replications with lowest identifier

Status
Not open for further replies.

WILKIEB

Programmer
Apr 27, 2005
5
US
I have a tables that has replicated rows. The only thing different is the FLD_ID. I need to select into a temp table the one with the lowest FLD_ID. The following gives me the replicated ones. Any help?
SELECT
*FROM
folder_id
WHERE
EXISTS (SELECT NULL
FROM folder_id b
WHERE
b.stock = folder_id.stock
AND b.part = folder_id.part
GROUP BY b.a_stock , b.part
HAVING folder_id.fld_id < MAX(b.fld_id))

table looks like this.
fld_id stock part
100 4 991
101 4 991
102 4 991
103 5 431
104 6 881
105 6 881

I need a temp table with this.
fld_id stock part
100 4 991
104 6 881

 
What should happen with 4th row (103/5/431)?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Nothing, I only want rows that are in the table more than once.
 
Will this work:
Code:
select stock, part, min(fld_id)
from folder_id
group by stock, part
having count(*) > 1

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top