Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- COUNT function
select COUNT(emp_id) from employee;

-- GROUP BY clause
select office_location, count(emp_id) from employee group by office_location;

-- HAVING clause
select office_location, count(emp_id) from employee group by office_location having office_location = 'Palo Alto';
11 changes: 11 additions & 0 deletions sql-queries/identify-duplicate-values/identify-duplicate-rows.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- duplicate values in one column
SELECT emp_id, COUNT(emp_id)
FROM employee
GROUP BY emp_id
HAVING COUNT(emp_id) > 1;

-- duplicate values in multiple columns
SELECT emp_id, first_name, last_name, COUNT(*)
FROM employee
GROUP BY emp_id, first_name, last_name
HAVING COUNT(*) > 1;
34 changes: 34 additions & 0 deletions sql-queries/identify-duplicate-values/sample-dataset.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE TABLE employee (
emp_id INT,
first_name VARCHAR(128),
last_name VARCHAR(128),
email VARCHAR(128),
office_location VARCHAR(128)
);

-- insert all unique records
INSERT INTO
employee (emp_id, first_name, last_name, email, office_location)
VALUES
(1, 'John', 'Doe', 'john.doe@baeldung.com', 'New York'),
(2, 'Tom', 'Fisk', 'tom.fisk@baeldung.com', 'Palo Alto'),
(3, 'Linda', 'Miller', 'linda.miller@baeldung.com', 'Chicago'),
(4, 'Jessica', 'Williams', 'jessica.williams@baeldung.com', 'Palo Alto');

-- insert records with one duplicated column
INSERT INTO
employee (emp_id, first_name, last_name, email, office_location)
VALUES
(1, 'Emma', 'Jackson', 'emma.jackson@baeldung.com', 'Austin'),
(3, 'Donald', 'Smith', 'donald.smith@baeldung.com', 'Seattle'),
(4, 'Olivia', 'Davis', 'olivia.davis@baeldung.com', 'Boston');

-- insert records with multiple duplicated columns
INSERT INTO
employee (emp_id, first_name, last_name, email, office_location)
VALUES
(2, 'Tom', 'Fisk', 'tom.fisk@baeldung.com', 'Palo Alto'),
(3, 'Linda', 'Miller', 'linda.miller@baeldung.com', 'Chicago'),
(2, 'Tom', 'Fisk', 'tom.fisk@baeldung.com', 'Palo Alto'),
(3, 'Linda', 'Miller', 'linda.miller@baeldung.com', 'Chicago'),
(2, 'Tom', 'Fisk', 'tom.fisk@baeldung.com', 'Palo Alto');