Using this statement:
select * from qvalues where rowid ,name,compound in (
select rowid,name,compound from qvalues where rowid in (select rowid from batchinfo where instrument='tf1')
group by rowid,name,compound
having COUNT(*)>1
)
group by rowid,name,compound
having rid=min(rid)
This error occurs:
Msg 4145, Level 15, State 1, Line 3 An expression of non-boolean type specified in a context where a condition is expected, near ','. Msg 156, Level 15, State 1, Line 8 Incorrect syntax near the keyword 'group'.
What is wrong with this SQL statement? I need to find all the occurrences of those three fields in the table having min(rid)
.
Update Using this query, the outer select is not working. What am I doing wrong?
select * from qvalues where rid not in (
select q.rowid, q.name, q.compound, 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)
I think this is equivalent to what you're trying to achieve.
The final
having min(rid)
needs to have comparisonSaying that, there is no associated GROUP BY which you can see if you rearrange your code snippet
Edit: reformulated:
And your original error probably comes from a lack of alias of the derived table, coupled with the fact that SQL Server does not support multi-column IN. I use EXISTS not JOIN because you may get more rows from qvalues JOIN batchinfo than you expect (based on Joe's answer)