SQL is the most important skill for a data scientist. Yes. It’s true. Relational Database Management is an important part of Data Science and SQL is the most-used language in data science, according to the 10,000+ data professionals who responded to StackOverflow's 2020 survey. Follow along and check the 23 most common and advanced SQL Interview Questions Data Scientists and Machine Learning Engineers must be prepared before their next ML or Data Science Interview.
Normalization is basically to design a database schema such that duplicate and redundant data is avoided. If the same information is repeated in multiple places in the database, there is the risk that it is updated in one place but not the other, leading to data corruption.
There is a number of normalization levels from 1. normal form through 5. normal form. Each normal form describes how to get rid of some specific problem.
By having a database with normalization errors, you open the risk of getting invalid or corrupt data into the database. Since data "lives forever" it is very hard to get rid of corrupt data when first it has entered the database.
Data definition language (DDL) commands are the commands which are used to define the database. CREATE, ALTER, DROP and TRUNCATE are some common DDL commands.
Data manipulation language (DML) commands are commands which are used for manipulation or modification of data. INSERT, UPDATE and DELETE are some common DML commands.
Write a SQL query to find all duplicate emails in a table named Person.
Table: Customers.
+----+---------+
| 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.
Since all emails are in lowercase we can simply group by email and print those that have a count > 1.
SELECT EMAIL
FROM PERSON
GROUP BY EMAIL
HAVING COUNT(*)>1We have a table
ID NAME EMAIL
1 John asd@asd.com
2 Sam asd@asd.com
3 Tom asd@asd.com
4 Bob bob@asd.com
5 Tom asd@asd.comI want is to get duplicates with the same email and name.
Simply group on both of the columns:
SELECT
name, email, COUNT(*) as CountOf
FROM
users
GROUP BY
name, email
HAVING
COUNT(*) > 1It is the process of improving the performance of the database by adding redundant data.
In database systems, Collation specifies how data is sorted and compared in a database. Collation provides the sorting rules, case, and accent sensitivity properties for the data in the database.
For example, when you run a query using the ORDER BY clause, collation determines whether or not uppercase letters and lowercase letters are treated the same.
INNER JOIN, OUTER JOIN, FULL OUTER JOIN?An inner join retrieve the matched rows only.
Whereas an outer join retrieve the matched rows from one table and all rows in other table ....the result depends on which one you are using:
Retrieve the matched rows only, that is, A intersect B.
SELECT *
FROM dbo.Students S
INNER JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDSelect all records from the first table, and any records in the second table that match the joined keys.
SELECT *
FROM dbo.Students S
LEFT JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDSelect all records from the second table, and any records in the first table that match the joined keys.
SELECT *
FROM dbo.Students S
FULL JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDJOIN and UNION?UNION puts lines from queries after each other, while JOIN makes a cartesian product and subsets it -- completely different operations. Trivial example of UNION:
mysql> SELECT 23 AS bah
-> UNION
-> SELECT 45 AS bah;
+-----+
| bah |
+-----+
| 23 |
| 45 |
+-----+
2 rows in set (0.00 sec)similary trivial example of JOIN:
mysql> SELECT * FROM
-> (SELECT 23 AS bah) AS foo
-> JOIN
-> (SELECT 45 AS bah) AS bar
-> ON (33=33);
+-----+-----+
| foo | bar |
+-----+-----+
| 23 | 45 |
+-----+-----+
1 row in set (0.01 sec)UNION and UNION ALL? UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not.
There is a performance hit when using UNION instead of UNION ALL, since the database server must do additional work to remove the duplicate rows, but usually you do not want the duplicates (especially when developing reports).
SELECT 'foo' AS bar UNION SELECT 'foo' AS barResult:
+-----+
| bar |
+-----+
| foo |
+-----+
1 row in set (0.00 sec)SELECT 'foo' AS bar UNION ALL SELECT 'foo' AS barResult:
+-----+
| bar |
+-----+
| foo |
| foo |
+-----+
2 rows in set (0.00 sec)TRUNCATE and DELETE operations effect Identity?UNION, MINUS and INTERSECT?GROUP BY group (greatest-n-per-group problem)?Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....
Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....
Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...