database:

Employees Earning More Than Their Managers

# SQL Schema: Create table If Not Exists Employee (Id int, Name varchar(255), Salary int, ManagerId int) Truncate table Employee insert into Employee (Id, Name, Salary, ManagerId) values ('1', 'Joe', '70000', '3') insert into Employee (Id, Name, Salary, ManagerId) values ('2', 'Henry', '80000', '4') insert into Employee (Id, Name, Salary, ManagerId) values ('3', 'Sam', '60000', 'None') insert into Employee (Id, Name, Salary, ManagerId) values ('4', 'Max', '90000', 'None') The Employee table holds all employees including their managers.

by lek tin in "database" access_time 2-min read

Duplicate Emails

Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Email | +----+---------+ | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | +----+---------+ For example, your query should return the following for the above table: +---------+ | Email | +---------+ | a@b.com | +---------+ Note: All emails are in lowercase. Solution # Write your MySQL query statement below SELECT email FROM Person WHERE email IN ( SELECT email FROM Person GROUP BY email HAVING COUNT(*) > 1 ) GROUP BY email

by lek tin in "database" access_time 1-min read

Combine Two Tables

Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address +-------------+---------+ | Column Name | Type | +-------------+---------+ | AddressId | int | | PersonId | int | | City | varchar | | State | varchar | +-------------+---------+ AddressId is the primary key column for this table.

by lek tin in "database" access_time 1-min read