Answer the question
In order to leave comments, you need to log in
An interesting (seemingly simple) SQL query?
Just now at the interview, they asked a problem about the following sample:
There are 2 related tables. Table A stores identifiers from table B. It is necessary to select from table B all records whose identifiers are not in table A.
Immediately wrote the following
SELECT * FROM b WHERE b.id NOT IN (SELECT a.idB FROM a)
Answer the question
In order to leave comments, you need to log in
Well, what's interesting here?
Find out the answer given a homework assignment?
I would argue that with a >80% chance, using really simple rather than compound queries will be more efficient, resulting in:
1. Easier to write
2. Runs faster
3. Thankfully cached
4. Easier to upgrade
It can be third and fourth. And how faster it will depend on the DBMS, version, indexes, volumes and distribution of data, etc.
Perhaps they wanted several options and clever reasoning from you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question