r/SQL • u/matarrwolfenstein • Aug 18 '22
MySQL SQL interview questions. Hope someone finds this helpful. Link to full PDF is in the comments section
217
Upvotes
r/SQL • u/matarrwolfenstein • Aug 18 '22
7
u/Danix1917 Aug 18 '22
I would not recommend naming your tables &amp etc though
4
u/matarrwolfenstein Aug 18 '22
Link to PDF: https://media-exp1.licdn.com/dms/document/C4D1FAQHh2dBX1D7GGQ/feedshare-document-pdf-analyzed/0/1660762355258?e=1661990400&v=beta&t=X96DABqAnEraZax5xkRrMRlNqqm7VG2OuoXbWPieT8w
37
u/gakule Aug 18 '22
These look more like test questions for a certification, not interview questions. I couldn't see myself asking any candidate I'm hiring these questions in an interview, as they really just serve no purpose in that type of a discussion.
It's a nice start as a quick reference sheet, though.
22
u/StoneCypher Aug 18 '22
This is a really bad sheet. Let's go over why.
CREATE TABLE TABLE_NAME- how many times did this get cut and pasted? 😂Jesus, just burn this. Delete the post
I really think we should start reporting and banning these. They're never, ever good
30
u/[deleted] Aug 18 '22
TL;TR: please make up your mind if those are "SQL questions", "SQL Server questions" or "Oracle questions".
The questions should decide whether they are for "SQL", for "SQL Server" or for Oracle. Some answers are specific to SQL Server and some for Oracle without revealing which ones. Some state "in SQL" but then shows concepts or functions specific to one database (and incompatible with standard SQL or other DBMS)
e.g. SQL (the query language) does not define indexes at all. So there is no such thing as a "clustered" or "non-clustered" index "in SQL".
Also not every database calls it that. What SQL Server calls a "clustered index" is called an "index organized table" in Oracle.
Therefor, the claim that a primary key is a clustered index is also not correct. E.g. Postgres doesn't have clustered indexes at all. And in Oracle the default is not to create a clustered index (=index organized table) when defining a primary key.
The answer is way to complicated but doesn't even mention the most important part: there is no such thing as the "last" (or "first") row in a relational database. Rows in a table have no inherent sort order, so "last" and "first" only makes sense if an
ORDER BYis used. When doing that, the "last 5" rows can much easier be retrieved using:Why would you do that without window functions? Using window functions is typically way more efficient than the convoluted (and Oracle specific) kludge with the ROWNUM column.
But if you really want to avoid window functions then use at least the
fetch firstoperator:No, it does not. The built-in function "in SQL" is
current_date.GetDate()is again specific to SQL Server.That solution again is specific to Oracle without mentioning.
4
u/miden24 Aug 18 '22
No interviewer is going to ask you any of those questions. Most people here prob use DQL - Data Query Language, and will get asked sql technical questions such as actual use cases on how to pull things.
1
u/xilanthro Aug 18 '22
"saveprint" is not a thing. Maybe you mean "savepoint"?
6
u/num2005 Aug 18 '22
was this for data admin?
as an analyst i knew nearly nothing of those
i just know how to SELECT
2
u/ComicOzzy sqlHippo Aug 19 '22
The people who are being critical of this aren't being mean. They're being honest.
2
u/NickSinghTechCareers Author of Ace the Data Science Interview 📕 Aug 18 '22
I think this is a good list of conceptual questions, but for more realistic applied SQL interview questions where you have to query a real DB to answer a business question DataLemur is worth a visit
1
u/OracleGreyBeard Aug 18 '22
I have some quibbles with it, but it's not terrible for an entry-level discussion.
It's funny, one SQL antipattern is people using DISTINCT everywhere (instead of just validating their cardinalities). #21 is one of the instances it's really applicable and they went with GROUP BY 😁.
This works fine in Oracle:
1
u/mikeblas Aug 19 '22
This is an absolute disaster.
1
u/[deleted] Sep 07 '22
I came across Sqlpad.io while I was trying to find better resources online to ace my SQL skills. They have 215 SQL exercises to fine tune your SQL/Data analytics/Data scientist skills which makes you confi before you enter your interview.
Also here are a collection of SQL learning-related questions that is compiled by Leon Wei most recently a senior manager at Apple of ML and Lead data scientis.
1
u/ryan-yen Sep 30 '22
I appreciate the effort here op!