-1

Want to check if there are double items in Column Naam in Table zeeboot , and then i show them in a combobox. Show the result is not the problem but the Statement is .

This is working

Select Naam FROM zeeboot GROUP BY Naam HAVING COUNT(Naam) > 1

But also i want to filter if the Naam is double check if Bijzonderheden IS NULL or empty

Show double Naam where Bijzonderheden is empty

Tried this but the outcome is not good.

SELECT Naam 
FROM zeeboot 
GROUP BY Naam 
HAVING COUNT(Naam) > 1 
AND SUM(CASE WHEN Bijzonderheden IS NULL OR Bijzonderheden = '' 
THEN 1 ELSE 0 END) > 0

And i think there is another thing , what if there are double Naam and both Bijzonderheden are not empty

Using SQL Server Compact Edition database version 3.5

1 Answer 1

0

Based on your problem description, I came up with a sample table and data and here is what I recommend. The moment you try to use the two predicates in the "HAVING" section, it will not work. So instead, using a sub-query is the way to go.

By the way, when submitting questions related to queries, it will help us if you provide a good code sample to reproduce the scenario. I used http://sqlfiddle.com/ to write and test the code below.

CREATE TABLE zeeboot (
  Naam INTEGER,
  Bijzonderheden);

INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (1,1);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (1,2);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (1,NULL);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (2,1);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (2,2);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (2,3);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (2,'');
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (3,1);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (4,1);
INSERT INTO zeeboot(Naam, Bijzonderheden) VALUES (5,'');

SELECT O.Naam 
  FROM zeeboot O
 WHERE EXISTS (SELECT I.Naam 
                 FROM zeeboot I
                WHERE IFNULL(I.Bijzonderheden,'') = ''
                  AND I.Naam = O.Naam)
 GROUP BY O.Naam
HAVING COUNT(O.Naam) > 1;
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply Sal , i have this error . System.Data.SqlServerCe.SqlCeException: 'There was an error parsing the query. [ Token line number = 3,Token line offset = 3,Token in error = From ]'
Why are you using SQL Server Compact Edition (System.Data.SqlServerCe) library? You should be using System.Data.Sqlite or Microsoft.Data.Sqlite library. Or perhaps, why did you post your question with the tag "sqlite" if you are using SQL Server Compact Edition
Oh sorry Sal Young i see it now , my mistake . Edited my Question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.