2010-12-14 54 views
0
select min(q.rid) 
    from qvalues q 
     inner join batchinfo b 
      on q.rowid = b.rowid 
       and b.instrument = 'tf1' 
    group by q.rowid, q.name, q.compound 
    having count(*) > 1 
  1. au lieu de sélectionner le min (Rid) Comment puis-je supprimer tout sauf min (Rid)?
  2. comment supprimer tout sauf pour max (débarrasser)?

s'il vous plaît noter que je veux supprimer uniquement les valeurs qui ont le même rowid, le nom et composésupprimer des lignes qui n'ont pas min (Rid)

+0

[ Question liée] (http://stackoverflow.com/questions/4443451/expression-of-non-boolean-type/4443497#4443497) –

Répondre

0
begin transaction 

delete from [table] 
where rid != 
(select min(q.rid) 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and rowid != 
(select q.rowid 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and name != 
(select q.name 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 
and compound != 
(select q.compound 
from qvalues q 
    inner join batchinfo b 
     on q.rowid = b.rowid 
      and b.instrument = 'tf1' 
group by q.rowid, q.name, q.compound 
having count(*) > 1) 

pour supprimer tous, mais max, vous faites la même chose avec la syntaxe max

+0

@ramy merci, mais s'il vous plaît noter que je veux supprimer uniquement les valeurs qui ont le même rowid , nom et composé comme dans cet ensemble –

+0

mis à jour ........ – Ramy

+0

aussi, j'ai ajouté une transaction de début a t le début si vous utilisez réellement ceci sur une DB de production. Si cela vous convient, utilisez "commit" à la fin. sinon utilisez "rollback" – Ramy